🐾PurrNet Docs
Plug & Play

Network Animator

NetworkAnimator is a plug-and-play component that automatically replicates Animator parameters, layer weights, and state transitions to every observer. Attach it alongside a NetworkIdentity — no code required for basic setups.

How it works

NetworkAnimator watches the local Animator component for parameter changes each tick. When a parameter value differs from its last-synced value by more than the configured tolerance, a compact parameter update is sent to all observers. On remote clients, the incoming values are written directly to their local Animator, which drives the state machine normally — no bespoke transition code required.

State transitions fire naturally on every client because the state machine reacts to the replicated parameter values, just as it would to local input.

Inspector settings

ParameterTypeDefaultDescription
Sync ParametersbooltrueAutomatically synchronise all Animator parameters (bool, int, float, trigger) to every observer.
Sync LayersbooltrueSynchronise layer weights so blended layers (e.g. an upper-body overlay) match across clients.
SendIntervalTicksint1How many network ticks to wait between Animator state broadcasts. Higher values reduce bandwidth at the cost of animation smoothness.
Owner AuthbooltrueWhen enabled, the owning client drives the Animator and syncs to all others. Disable to make the server the sole animation authority.

Owner-driven animation

The most common pattern is to let the owner set Animator parameters based on their local input, then have NetworkAnimator replicate those parameters to all other clients. Use the isOwner guard so non-authority clients never write to the Animator directly.

CharacterAnimator.cs
using PurrNet;
using UnityEngine;

[RequireComponent(typeof(NetworkAnimator))]
public class CharacterAnimator : NetworkBehaviour
{
    [SerializeField] private Animator _animator;
    [SerializeField] private CharacterController _controller;

    // Animator parameter hashes — computed once for performance
    private static readonly int SpeedHash     = Animator.StringToHash("Speed");
    private static readonly int IsGroundedHash = Animator.StringToHash("IsGrounded");
    private static readonly int JumpHash      = Animator.StringToHash("Jump");

    private void Update()
    {
        // Only the owner drives the Animator.
        // NetworkAnimator replicates these values to everyone else.
        if (!isOwner) return;

        float speed = new Vector2(_controller.velocity.x, _controller.velocity.z).magnitude;
        _animator.SetFloat(SpeedHash, speed, 0.1f, Time.deltaTime);
        _animator.SetBool(IsGroundedHash, _controller.isGrounded);
    }

    // Called by input system on the owner
    public void TriggerJump()
    {
        if (!isOwner) return;
        _animator.SetTrigger(JumpHash);
    }
}

Use triggers on reliable channels

Triggers are one-shot events — if the packet containing a trigger is dropped, the animation never fires on remote clients. Send trigger-bearing RPCs on a reliable channel, or use a counter-based SyncVar<int>as a poor-man's reliable trigger.

Server-authoritative animation

For NPCs or physics-driven characters where the server controls movement, set Owner Auth to false. The server's Animator values are broadcast to all clients, and no client can override them.

EnemyAI.cs
using PurrNet;
using UnityEngine;
using UnityEngine.AI;

// Owner Auth = false on the NetworkAnimator inspector — server drives animation
public class EnemyAI : NetworkBehaviour
{
    [SerializeField] private Animator _animator;
    [SerializeField] private NavMeshAgent _agent;

    private static readonly int SpeedHash   = Animator.StringToHash("Speed");
    private static readonly int AttackHash  = Animator.StringToHash("Attack");

    private void Update()
    {
        // Only server updates the Animator — replicated to all clients
        if (!isServer) return;

        _animator.SetFloat(SpeedHash, _agent.velocity.magnitude, 0.15f, Time.deltaTime);
    }

    // Server-side only: trigger an attack animation on all clients
    public void PerformAttack()
    {
        if (!isServer) return;
        _animator.SetTrigger(AttackHash);
    }
}

Situational example — character with idle, run, and jump states

A typical third-person character uses three base states driven by two parameters: a float Speed and a trigger Jump. The owner sets these from the input system; NetworkAnimator handles the rest.

PlayerCharacter.cs
// Animator state machine has:
//   Idle  → (Speed > 0.1)  → Run
//   Run   → (Speed < 0.1)  → Idle
//   Any   → [Jump trigger] → Jump → (exit time) → Idle/Run
//
// NetworkAnimator on the same GameObject with Owner Auth = true.

using PurrNet;
using UnityEngine;

public class PlayerCharacter : NetworkBehaviour
{
    [SerializeField] private Animator        _animator;
    [SerializeField] private CharacterController _cc;

    private static readonly int SpeedHash = Animator.StringToHash("Speed");
    private static readonly int JumpHash  = Animator.StringToHash("Jump");

    private Vector3 _velocity;
    private const float Gravity   = -9.81f;
    private const float JumpForce =  5.0f;
    private const float MoveSpeed =  4.0f;

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

        Vector2 input = new Vector2(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
        Vector3 move  = new Vector3(input.x, 0, input.y) * MoveSpeed;

        if (_cc.isGrounded)
        {
            _velocity.y = -0.5f;
            if (Input.GetButtonDown("Jump"))
            {
                _velocity.y = JumpForce;
                _animator.SetTrigger(JumpHash); // NetworkAnimator replicates this trigger
            }
        }
        else
        {
            _velocity.y += Gravity * Time.deltaTime;
        }

        _cc.Move((move + _velocity) * Time.deltaTime);
        _animator.SetFloat(SpeedHash, move.magnitude, 0.08f, Time.deltaTime);
    }
}

Never call Animator.Play() on non-authority clients

Calling Animator.Play() or Animator.CrossFade() on a remote client will fight with the incoming parameter syncs and cause visual glitching. Reserve direct state transitions to the authority side only, and let the state machine handle transitions from replicated parameter values everywhere else.

NetworkAnimator vs manual SyncVar animation

For simple two-state toggles (visible/hidden, open/closed door), a SyncVar<bool> with an onChanged callback that calls Animator.SetBool() is lighter than NetworkAnimator. Use NetworkAnimator when you have several parameters or complex blend trees.