Network Mecanim Animator
Overview
The NetworkMecanimAnimator
synchronises the state and values of the parameters held by an associated Unity mecanim Animator
component.
It is important to note that because Unity's Animator
component cannot be rewound and re-simulated (it is designed to run forward only) and because it cannot be accurately set to a tick's state, it cannot be relied on for tick accurate animations.
Because of this "forward only" limitation NetworkMecanimAnimator
does not attempt to resimulate, and NetworkMecanimAnimator
will only sync the Animator
component from the State Authority to Proxies. The Input Authority should also apply changes to the Animator on Forward ticks.
NOTE: There are many cases where using NetworkMecanimAnimator
may not be the ideal answer for syncing animations. Be sure to reference the Animation Concepts and Patterns section for more information.
Usage
Any controller code should apply inputs to the State Authority and the Input Authority, and not to Proxies. This Automatically will be the case if you make use of Fusion's input system.
C#
void FixedUpdateNetwork()
{
// Only apply changes to the Animator if input is available
// (which is true for StateAuthority and InputAuthority),
// and only on Forward ticks (resimulation should be ignored).
if (GetInput(out var input) && Runner.IsForward)
{
// Apply inputs to Animator
}
}
Shared Mode without using Fusion Input Handling
Shared Mode does not require the use of the Fusion Input System, and you can handle input gathering and application yourself. In this case, be sure to restrict inputs to only apply on the State Authority.
C#
void FixedUpdateNetwork()
{
// In Shared Mode:
// Only apply changes to the Animator on the StateAuthority.
if (HasStateAuthority)
{
// Apply inputs to Animator
}
}
SetTrigger()
The pass-through NetworkMecanimAnimator.SetTrigger()
methods should used instead of Animator.SetTrigger()
calls, as triggers are transient and it is possible for the backing bool to reset to false before NetworkMecanimAnimator
captures the values of the Animator
component. There is also a passThroughOnInputAuthority
option for NetworkMecanimAnimator.SetTrigger()
, which immediately passes through to Animator.SetTrigger()
on the Input Authority, as a convenience.