Loading...
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. Commands
Scene 7. Team based
Scene 8. Connected Entities
Each scene also 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 Play Mode, 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 configure individual Prefabs' persistent, authoritative and network connect/disconnect settings. There's much more information on the CoherenceSync page.
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 specific colors that signify if they are local or networked.
In the Hierarchy of the scene you can see three core Prefabs:
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 how replication works 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:
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 alternatively to 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 how replication works 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 its 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 affecting 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 how replication works 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:
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 disconnecting/reconnecting via the interface without refreshing the scene.
Coherence Entity Character
(remember to 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.
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 whether 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 how replication works for each.
Core Scene Setup
and Coherence Setup
are present in all scenes and described in detail on page.
Core Scene Setup
and Coherence Setup
are present in all scenes and described in detail on page.
Core Scene Setup
and Coherence Setup
are present in all scenes and described in detail on page.
This scene will show you how easy it is to set up Networking in your Unity project and sync GameObject transforms and 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 the 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 parameters Transform; 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 how replication works for each.
You can read more about synchronizing animations in the Animations section.
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, and 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 its Uniqueness
property which means the Server will only allow one instance of this object to exist at a time. It also has its Lifetime
setting set to Session Based
this will cause the object to be deleted when its 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 clean up 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 whether 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 handles the Adopt call and requests 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 how replication works for each.
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 its Entity destroyed as well.
To learn more, see Connected 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 how replication works for each.
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
(remember to 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 how the replication works for each of them.