Network state sync animation
Last updated
Last updated
You can use a network state to synchronize playback of an animation. The example on this page shows how you can play and pause an animation.
This example is similar to that shown in Network state animation start/stop. However, the arrangement shown on this page ensures that the timeline of the animation is synchronized across all users in a session. If you use only the play and pause commands, the animation can be at different stages depending on when users join the session, or can drift out of sync over long periods of time.
This example uses three networks states:
The object to be animated includes an Animator component, and a Network State Trigger_Synced Animation
script.
Another network state is linked to the Play Controller State
property of the Network State Trigger_Synced Animation
script. This network state synchronizes whether the animation is playing.
Another network state is linked to the Pause Time Value State
property of the Network State Trigger_Synced Animation
script. This network state synchronizes the point on the animation timeline where the animation is paused.
The following diagram shows an example of how to arrange the components in Unity, and the required references.
To set the animation to play on load, set the Current State
property to 1
in the SyncedAnimation_Play
game object (blue in the following diagram), not the SyncedAnimation_Play/Pause_object
game object (green in the following diagram).