Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Welcome to the first scene of the coherence Network Playground. This scene will show you how easy it is to set up networking in your Unity project and sync GameObject transforms across the network.
In this example, each client will have a player character to move by clicking on the map to make the entity move to that location. Each client will only have control of its local entity.
In the Hierarchy of the Scene you can see three core Prefabs.
Core Scene Setup
and Coherence Setup
are present in all (Network Playground) Scenes and described in detail on Start Tutorial page.
Coherence Entity Character
is the Prefab that will change per Scene with different functionality. It has a standard CharacterController
and Rigidbody
as well as an Agent
script which will handle movement through the Input Manager
in the Core Scene Setup
prefab.
Coherence Entity Character
(always change the prefab, not the instance) is located in the Resources folder. The UnityEngine.Transform
and position
are ticked to sync. All other settings (persistence and authority) use the default settings. This entity will be session based, no authority handover and no adoption will take place, when a client leaves.
The On Network Instantiation
event is used to change the color of the mesh and recalculate the RigidBody collisions. That's it.
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.
The Network Playground project is a series of scenes with different features of coherence for you to pick through and learn.
They will teach you the fundamentals that should set you on your way to creating a multiplayer game.
Each Scene in this Network Playground Project shows you something new:
Scene 1. Synchronizing Transforms
Scene 2. Physics
Scene 3. Persistence
Scene 4. Synchronizing Animations and Custom Variables
Scene 5. AI Navigation
Scene 6. Commands
Scene 7. Team based
Scene 8. Connected Entities
Each scene comes with a few helpful core components.
This Prefab stores all the generic things that make up these simple Scenes.
Main Camera
Global Volume
Directional Light
Environment (Ground, Walls etc)
Navigation Interface
To move between the Scenes without having to enter and exit playmode, useful when testing the standalone build.
Input Manager
Input Manager that uses Raycasting to send a message to the GameObject (with a collider) that it hit.
This Prefab includes all of the things that make coherence work.
Interface
Canvas UI that handles Connection/Disconnection dialog and what address to connect.
Event System
Event system to interact with any UI in the scene.
coherence Live Query
Game Object/Component with a query radius that coherence uses to ask the server "What is happening in the query radius?" so it does not query unnecessarily big areas of large worlds. You can find more information here.
coherence Mono Bridge
GameObject/Component to transform the Mono based CoherenceSync component to archetypes so all data can be processed as ECS code.
We use this component on anything that we require to be networked, whether this is a playable character, NPC (non playing character), an object (ball, weapon, banana, car, plant etc) or any Game/Input Managers that require to sync data between Clients/Simulators/Servers.
It scans the inspector for attached components and allows us to sync those component values (as long as they are public) and communicate them to other clients. It also allows us to set individual Prefabs persistent, authoritative and network connect/disconnect settings. There's much more information on the CoherenceSync page
This scene will show you how to use coherence to sync GameObject transforms and Physics objects across the network.
In this example, each client will have its own player character to move. Left-clicking on the map will make the entity move to that location. Right-clicking will spawn local physics based objects that all player characters can interact with. Each client will only have control over its local entity.
In the Hierarchy of the Scene you can see three core Prefabs:
Core Scene Setup
and Coherence Setup
are present in all scenes and described in detail on Start Tutorial page.
Coherence Entity
is the prefab that will change per Scene with different functionality. It has a standard CharacterController
and Rigidbody
as well as an Agent
script which will handle movement functionality through the Input Manager
in the Core Scene Setup
prefab.
Coherence Connection Events
handles overall Scene connectivity. Additionally, it removes all Entities with coherenceSync
from the Scene to demo disconnection/reconnection via the Interface without refreshing the Scene.
Coherence Entity Character
(always change the prefab, not the instance) is located in the Resources folder. The UnityEngine.Transform
and position
are ticked to sync. All other settings (persistence and authority) use the default settings. This entity will be session based, no authority handover and no adoption will take place, when a client leaves.
The On Network Instantiation
event is used to change the colour of the mesh.
The Physics Entity Spawner
is a simple script to instantiate a Coherence Entity Physics
Prefab with a coherenceSync component that replicates the transform and position. The component also changes the material based on if it is locally simulated or synced over the network.
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.
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.
This scene demonstrates usage of connected entities.
This scene shares the moving entities that were in a few previous scenes but also has added functionality.
Right-clicking on a non-local entity causes the local entity to start moving towards it while also displaying an arrow pointed at the target. When the entity reaches this target it will parent itself under it as a child, setting the target as its connected entity.
From this point onward, until the entity disconnects by moving or otherwise, the entity will be smaller and parented to this target. When the target moves the local entity will move with it as one.
This type of connection can also cause issues. For example if the client controlling the parent entity disconnects, destroying its entity, any client whose entity was a child of that destroyed entity will have his entity destroyed as well.
To learn more about connected entities see .
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.
This scene will show you how coherence can be used to make a basic team based game.
In this example each client has one character they can control with click to move input. When connecting the player will be prompted to select a team they wish to join.
This selection will be synced via a TeamIndex
field in the Sample Team Agent
component.
The Target Area
object is a unique gameobject that is shared among clients and moves around the grid, specifying a particular part of the field every time it jumps. When arriving at it's final position this object checks which team has the most players inside the specified area and awards that team a point.
The team colors and score are managed by another unique object called Team Assigner
. This object has a synced string variable called encodedScores
which is used to sync the team scores between clients.
Because both the Team Assigner
and Target Area
are persistent we can disconnect from the server and the game state will be preserved as long as the server is alive, even if no clients are connected at all.
Notice that the number of teams and their colors, set in the Team Assigner, are not synced. This means it could be possible to create different clients with different colors without them effecting each other.
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.
This scene will show you how easy it is to set up Networking in your Unity project and sync GameObject transforms and Physics objects across the network whilst keeping them persistent. As long as the server is running you can disconnect and re-connect, your world will persist.
In this example a right click will spawn local physics based objects that all other players will see. These physics objects will interact with each other and the physics for every object will be simulated locally on its authority. Clicking one of these objects will either take or relieve authority of the local client over the clicked object. You can disconnect and re-connect and the persistent entities will all remain.
The controls at the top right of the screen allow the spawning of a unique object that works very similarly to the other physics based objects. This bigger cube is set to No Duplicates
in it's Uniqueness
property which means the server will only allow one instance of this object to exist at a time. It also has it's Lifetime
setting set to Session Based
this will cause the object to be deleted when it's owner disconnects. Just like with the physics based objects, a player can claim authority over this object by clicking it. If that player would then disconnect all clients will have the unique object deleted.
In the Hierarchy of the Scene you can see three core Prefabs:
Core Scene Setup
and Coherence Setup
are present in all scenes and described in detail on Start Tutorial page.
Coherence Entity
is not present in this scene.
Input Manager
in the Core Scene Setup
prefab is set up to spawn a Sample Entity Physics Persistent
where a click is performed.
Coherence Connection Events
handles overall Scene connectivity. In this scene we use it to cleanup objects the client has authority over when disconnecting.
The Physics Entity Spawner
component is a simple script to instantiate a Coherence Entity Physics Persistent
prefab with a coherenceSync component that replicates the transform and position. The component also changes the material based on if it is locally simulated or synced over the network.
The Coherence Entity Physics
variants have an Entity Lifetime Type
set to Persistent
. This means it will remain in the world as long as the replication server is running, even if all clients disconnect. It also has Authority Transfer Style
set to Stealing
which means the entity can be "stolen" and simulated on a client requesting authority.
This is done via the Input Manager
in the Core Scene Setup
prefab. When the object is left-clicked, it sends the message "Adopt" to the GameObject on the specific Layer Mask "Physics Entities". The component called Coherence Handler
on Coherence Entity Physics
objects handle the Adopt call and requests the authority change via the coherenceSync component.
Coherence Handler
is a basic layer for handling Commands and Events, both sending and receiving. You can create your own or reuse and extend this for your project.
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.
This scene will show you how easy it is to set up Networking in your Unity project and send Network Commands to other clients. Network Commands are like sending direct messages to objects instead of syncing variable values.
In this example each client has one character they can control with click to move input. They can right-click on another Entity to send a command and that Entity will instantiate an Exclamation mark above their head.
In the Hierarchy of the Scene you can see three core Prefabs:
Core Scene Setup
and Coherence Setup
are present in all scenes and described in detail on Start Tutorial page.
Coherence Entity
is the prefab that will change per Scene with different functionality. It has a standard CharacterController
and Rigidbody
as well as an Agent
script which will handle movement functionality through the Input Manager
in the Core Scene Setup
prefab.
Coherence Entity
can send commands to other entities through the Coherence Handler
component. In the coherenceSync component we can open the bindings window and find a Methods
tab used for command setup. There we can find a method called ReceiveCommand
and beside it, an icon describing who the command will be sent to (Only to the objects authority or all clients).
In the game view in Play mode, Commands can be sent to other entities via the right click button. An exclamation mark asset will pop up above the right-clicked entity for all clients.
If we were to set this command to Authority Only
then only the objects' authority would receive this method call.
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.
This scene will show you how easy it is to set up Networking in your Unity project and sync non player characters that move around the world via Unity's Navmesh system.
In this example each client can spawn as many navigation agents as they wish, and these navigation agents will move intermittently to different locations on the grid. All navigation agents will be replicated across clients with a specific colors signifying if they are local or networked.
In the Hierarchy of the Scene you can see three core Prefabs:
Core Scene Setup
and Coherence Setup
are present in all scenes and described in detail on Start Tutorial page.
Coherence Connection Events
handles overall Scene connectivity. Additionally, it removes all Entities with coherenceSync
from the Scene to demo disconnection/reconnection via the Interface without refreshing the Scene.
Spawner
is a simple script to instantiate a Coherence Entity Nav Agent
prefab with a coherenceSync component that replicates the transform and position. The component also changes the material based on if it is locally simulated or synced over the network.
Coherence Entity Nav Agent
has a Nav Mesh Agent
component controlled via the Navigation Agent
script which every few seconds sets a new destination on the grid. It's not required to sync anything other than the Transform; position, rotation
parameter as the Nav Mesh Agent
settings only need to simulate locally.
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.