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.
+ RPC
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
LinearMixerTransition type and state.IsPlaying setter may differ slightly โ check the Animancer upgrade guide for your version.Download & Install
- Download the scripts below.
- Place them anywhere inside your Unity project's
Assets/folder (suggested:Assets/PurrNetAnimancer/). - Both scripts compile automatically โ no assembly definitions needed.
- Follow the setup steps below.
Setup
// โโ 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
| Parameter | Type | Default | Description |
|---|---|---|---|
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. |
CurrentClipName | string | โ | 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.
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.
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.
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
_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
_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
_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.