This scene will show you how easy it is to set up Networking in your Unity project and sync GameObject transforms, animations via the Animator parameters and customer variables.
In this example, each client will have its own player character to move, the beloved Unity RobotKyle asset. Type your name into the connect dialog box and connect. You can move around with WASD. When another player connects, their name is carried across and their transform and animation state is replicated.
In the Hierarchy of the scene you can see the two core prefabs Core Scene Setup
and Coherence Setup.
Both are present in all scenes and described in detail on Start Tutorial page.
Coherence Kyle
is taken from the Unity asset "Robot Kyle", with added components Rigidbody
, Character Controller
, and Animator
with the two animation states - Idle and Walk. The animation states are controlled by a speed parameter from the Agent
script. The scene also contains a Name Badge
script which gets the Connect Dialog
GameObject from the Core Scene Setup
and sets the color depending if it's local or networked.
Attached to Coherence Kyle
is a coherenceSync component which replicates the parametersTransform; position and rotation
, Animator; Speed[float]
and NameBadge; Name [string]
. The authority and persistence settings are set to their default values and the On Network Instantiation
event is used to change the color of the networked entities.
You can build this Scene via the Build Settings. Run the local Replication Server through the Window -> coherence -> Settings window and see how it works. You can try running multiple clients rather than just two and see replicating for each.
You can read more about synchronizing animations on the Animations section.