๐ŸพPurrNet Docs
Integration

Animancer Integration

PurrNetAnimancerSync is a drop-in component that synchronizes Animancer's code-driven animation system over PurrNet โ€” replicating clip playback, normalized time, speed, and pause state to all connected peers without touching Animator Controllers.

Animancer Clip SyncSimulated 150 ms RTT
Owner (You)
๐Ÿง
Idle
Looping ยท 1.5s
NormalizedTime0%
Play clip:
SyncVar
+ RPC
Observer (Peer)
๐Ÿง
Idle
Looping ยท 1.5s
NormalizedTime0%
Drift: 0 ms โ€” in sync โœ“
Observer corrects toward owner NormalizedTime at 8ร—/s when drift > 0.05.

What is Animancer?

Animancer (by Kybernetik) replaces Unity's Animator Controller with code-driven animation. Instead of a visual state machine graph, you call animancer.Play(clip) directly โ€” giving you full control over cross-fades, speeds, events, and layering from C# without any controller assets.

Because Animancer bypasses Animator Controllers, Unity's built-in NetworkAnimator and PurrNet's NetworkAnimator component cannot sync Animancer state. PurrNetAnimancerSync fills this gap by syncing clip indices and normalized time directly.

Animancer version

PurrNetAnimancerSync targets Animancer 8.x. If you are using an older version, the LinearMixerTransition type and state.IsPlaying setter may differ slightly โ€” check the Animancer upgrade guide for your version.

Download & Install

  1. Download the scripts below.
  2. Place them anywhere inside your Unity project's Assets/ folder (suggested: Assets/PurrNetAnimancer/).
  3. Both scripts compile automatically โ€” no assembly definitions needed.
  4. Follow the setup steps below.

Setup

Setup.cs
// โ”€โ”€ Step 1: Register clips in the Inspector โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
//
//  PurrNetAnimancerSync._registeredClips must contain every clip
//  you'll call Play() with. Example for a typical humanoid:
//
//  Index 0  โ†’  Idle
//  Index 1  โ†’  Walk
//  Index 2  โ†’  Run
//  Index 3  โ†’  Jump
//  Index 4  โ†’  Attack
//  Index 5  โ†’  Death
//
//  Assign the same AnimationClip assets in the same order on the PREFAB
//  so that all peers share the same indexโ†”clip mapping.

// โ”€โ”€ Step 2: Add components โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
//
//  Your character prefab component stack:
//    โœ“ Animator                    (required by AnimancerComponent)
//    โœ“ AnimancerComponent          (Animancer's runtime)
//    โœ“ PurrNetAnimancerSync        (this package โ€” syncs clip index + time)
//    โœ“ PurrNetAnimancerMixerSync   (optional โ€” only for blend-tree blending)
//    โœ“ NetworkIdentity             (PurrNet)
//    โœ“ YourCharacterController     (call _animSync.Play() from here)

// โ”€โ”€ Step 3: Wire the controller โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€

private PurrNetAnimancerSync _animSync;

private void Awake()
{
    _animSync = GetComponent<PurrNetAnimancerSync>();
}

private void Update()
{
    if (!isOwner) return;   // only the owner drives animations

    // Replace Animator.SetTrigger / Play with:
    _animSync.Play(clipIndex, fadeDuration);
    // or
    _animSync.Play(myAnimationClipReference);
}

API reference

ParameterTypeDefaultDescription
Play(int index, float fadeDuration = 0.25f)voidโ€”Play a registered clip by index on all peers. Owner only. Resets normalizedTime to 0 and immediately broadcasts to observers.
Play(AnimationClip clip, float fadeDuration = 0.25f)voidโ€”Play by clip reference. The clip must appear in _registeredClips โ€” its index is the network key.
SetSpeed(float speed)voidโ€”Set the playback speed SyncVar on all peers. Owner only.
Pause()voidโ€”Set state.IsPlaying = false on all peers via SyncVar. Owner only.
Resume()voidโ€”Resume a paused clip on all peers. Owner only.
CurrentClipNamestringโ€”The name of the currently playing registered clip, or 'None'. Read from any peer.
PlayMixer(float parameter)voidโ€”(PurrNetAnimancerMixerSync) Start the LinearMixerState and set its blend parameter. Call every frame in your movement controller.

Basic usage โ€” clip-based controller

Replace every animator.SetTrigger() / animator.Play() call with _animSync.Play(clip). The component handles replication.

AnimancerCharacter.cs
using PurrNet;
using Animancer;
using UnityEngine;

/// <summary>
/// Example character controller that uses PurrNetAnimancerSync.
/// Attach alongside AnimancerComponent and PurrNetAnimancerSync.
/// </summary>
public class AnimancerCharacter : NetworkBehaviour
{
    [Header("Animation Clips โ€” same order as PurrNetAnimancerSync._registeredClips")]
    [SerializeField] private AnimationClip _idle;
    [SerializeField] private AnimationClip _walk;
    [SerializeField] private AnimationClip _run;
    [SerializeField] private AnimationClip _jump;
    [SerializeField] private AnimationClip _attack;

    private PurrNetAnimancerSync _animSync;
    private CharacterController  _cc;
    private bool                 _isGrounded;

    private void Awake()
    {
        _animSync = GetComponent<PurrNetAnimancerSync>();
        _cc       = GetComponent<CharacterController>();
    }

    private void Update()
    {
        // Only the owner drives animation state
        if (!isOwner) return;

        float speed = new Vector2(_cc.velocity.x, _cc.velocity.z).magnitude;

        if (!_isGrounded)
            _animSync.Play(_jump, fadeDuration: 0.15f);
        else if (speed > 5f)
            _animSync.Play(_run);
        else if (speed > 0.1f)
            _animSync.Play(_walk);
        else
            _animSync.Play(_idle, fadeDuration: 0.3f);
    }

    // Call from your input handler on the owner
    public void OnAttackInput()
    {
        if (!isOwner) return;
        _animSync.Play(_attack, fadeDuration: 0.1f);
    }
}

Blend trees โ€” LinearMixerState sync

For locomotion blending (walk โ†” run based on speed), use PurrNetAnimancerMixerSync alongside the base component. It syncs the mixer parameter via a SyncVar<float> at a configurable interval so all peers see smooth blending.

AnimancerMoverController.cs
using PurrNet;
using Animancer;
using UnityEngine;

/// <summary>
/// Movement controller that blends Walk/Run via a LinearMixerState.
/// The mixer parameter (moveSpeed 0-6) is synced to all peers via SyncVar.
/// </summary>
public class AnimancerMoverController : NetworkBehaviour
{
    private PurrNetAnimancerSync      _animSync;
    private PurrNetAnimancerMixerSync _mixerSync;
    private CharacterController       _cc;

    private void Awake()
    {
        _animSync  = GetComponent<PurrNetAnimancerSync>();
        _mixerSync = GetComponent<PurrNetAnimancerMixerSync>();
        _cc        = GetComponent<CharacterController>();
    }

    private void Update()
    {
        if (!isOwner) return;

        float speed = new Vector2(_cc.velocity.x, _cc.velocity.z).magnitude;

        // PlayMixer starts the LinearMixerState and sets the parameter each frame.
        // PurrNetAnimancerMixerSync syncs the parameter to all peers at _syncInterval.
        _mixerSync.PlayMixer(speed);
    }
}

Animancer events โ€” syncing one-shot completion

Animancer's end-events fire only on the local machine. To notify the server when a one-shot animation (attack, roll, death) finishes, attach the event on the owner and send a ServerRpc โ€” keep gameplay logic out of the animation callback.

AnimancerEventSync.cs
using PurrNet;
using Animancer;
using UnityEngine;

/// <summary>
/// Shows how to sync Animancer end-events (one-shot attack finishing)
/// so all peers know when the animation completes.
/// </summary>
public class AnimancerEventSync : NetworkBehaviour
{
    [SerializeField] private AnimationClip _attack;
    [SerializeField] private AnimationClip _idle;

    private PurrNetAnimancerSync _animSync;
    private AnimancerComponent   _animancer;

    private void Awake()
    {
        _animSync = GetComponent<PurrNetAnimancerSync>();
        _animancer = GetComponent<AnimancerComponent>();
    }

    public void StartAttack()
    {
        if (!isOwner) return;

        // Clip index 3 = Attack in _registeredClips
        _animSync.Play(3, fadeDuration: 0.1f);

        // Attach an end-event only on the owner โ€” then RPC the completion
        var state = _animancer.Play(_attack, 0.1f);
        state.Events.OnEnd = OnAttackEnd;
    }

    private void OnAttackEnd()
    {
        // Return to idle on all peers
        _animSync.Play(0, fadeDuration: 0.2f);

        // Notify server to apply the hit โ€” decouple animation from gameplay
        NotifyAttackCompleteServerRpc();
    }

    [ServerRpc]
    private void NotifyAttackCompleteServerRpc()
    {
        // Server checks hit detection here โ€” not in the animation callback
        Debug.Log($"[Server] {gameObject.name} attack confirmed.");
    }
}

Register clips once on the prefab

Set _registeredClips on the prefab, not in code. All runtime instantiations share the same list, guaranteeing that index 2 always means "Run" on every peer. If you change the list order at runtime you will desync.

Late-join clients

A client that joins mid-session will receive the last-broadcast SyncVar values for _clipIndex and _speed. The first BroadcastNormalizedTime RPC (next sync interval) will correct any time drift. For critical one-shot clips (death, stagger), consider storing the last-played clip in a persistent SyncVar so late joiners can replay it.

Do not call animancer.Play() directly on non-owners

If your character controller also calls _animancer.Play() directly (outside of PurrNetAnimancerSync), non-owners will override the synced state and break replication. All playback must go through _animSync.Play() on the owner.