Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
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. Network Commands
Scene 7. Network Events
Each scene comes with a few helpful core components.
This Prefab stores all the generic things that make up these simple Scenes.
Main Camera
PostFX 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 Fundamentals page
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 each client will have it's own player character to move, we will click on the map to make the entity move to that location, simple click to move functionality and right click to spawn local physics based objects that all other player characters can interact with. Each client will only have control of its local entity. You can disconnect and re-connect and the persistent entities will all remain.
In the Hierarchy of the Scene you can see three core Prefabs:
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.
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.
Coherence Entity Physics Persistent
has 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.
The Auto Generate Persistance UUID
should be checked so that a unique identification string will be used to identify instances of this entity as unique. When the entity is spawned with this checked, it will generate its own UUID.
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 Persistent
handles 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.
Core Scene Setup
and Coherence Setup
are present in all scenes and described in detail in .
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 in Exploring the Network Playground.
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.
This scene will show you how easy it is to set up Networking in your Unity project and send Network Events to other clients. Network Commands is like sending a direct message to another player, without anyone else knowing. Network Events is like shouting out loud for anyone in the area to hear you.
In this example each client has one character they can control with click to move input. They can right-click anywhere on the grid and all entities 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 in Exploring the Network Playground.
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.
Network Events are still in development but this example shows a workaround using Commands. When an event is sent to an entity, Coherence Handler
finds all instances of coherenceSync and sends the event command to all these entities.
In the coherenceSync component, small "lightning bolt" icons are shown next to the tick boxes for the syncable properties. These icons signify that they are public methods rather than singular variables and that these methods can be called through the Coherence Handler
Event System, either to send or receive commands.
In the game view in Play mode, Commands can be sent to other entities via the right click button anywhere on the grid and an exclamation mark asset should pop up above all clients 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.
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 is like sending a direct message to another player, without anyone else knowing.
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 in Exploring the Network Playground.
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, small "lightning bolt" icons are displayed next to the tick boxes for the syncable properties. These icons signify that they are public methods rather than singular variables and that these methods can be called through the Coherence Handler
Event System, either to send or receive commands.
In the game view in Play mode, Commands can be sent to other entities via the right click button. An exclamation mark asset should pop up above the right-clicked entity, but only for the sending and the receiving client. No other clients will be made aware of this.
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.
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.
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 in .
You can read more about synchronizing animations on the section.
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 in Exploring the Network Playground.
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.
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 in Exploring the Network Playground.
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.