Replication Server
The Replication Server replicates the state of the world to all connected Clients and Simulators.
To understand what is happening in the game world, and to be able to contribute your simulated values, you need to connect to a Replication Server. The Replication Server acts as a central place where data is received from and distributed to interested clients.
You can connect to a Replication Server in the cloud, but we recommend that you first start one locally on your computer. coherence is designed so you can easily develop everything locally first before deploying to the cloud.
Replication Servers replicate data defined in schema files. The schema's inspector provides all the tools needed to start a Replication Server.
Run the Replication Server by clicking the run button.
A terminal/command line will pop up running your server locally
The port the Replication Server will use. Default:
32001
.The Replication Server frequency. Default:
60
.
You can also start the replication server from the coherence menu or by pressing ctrl+shift+alt+N.
If you're unsure where schema files are located, you can easily search through the project using Unity's project search window, witht:Coherence.SchemaAsset
To connect with multiple clients locally, publish a build for your platform (File > Build and Run
, details in Unity docs). Run the Replication Server and launch the build any number of times. You can also enter Play Mode in the Unity Editor.
For Mac Users: You can open new instances of an application from the Terminal:
Connecting to a Replication Server
When the replication server is running, you connect to it using the Connect
command from one of your component systems.
Connect to a Replication Server
After trying to connect you might be interested in knowing whether the connection succeeded. The Connect call will run asynchronously and take around 100 ms to finish, or longer if you connect to a remote server. One way is to poll the NetworkState once each tick until we know that it has succeeded. It is also possible to listen for a [network event]().
Check if we are connected
Check 'Run in Background' in the Unity settings under Project Settings -> Player so that the clients continue to run when not the active window.
Make sure that your system is actually run, for example by adding the [AlwaysUpdateSystem]
attribute to your system class. By default, Unity ECS will not run your system if it doesn't process any Entities.
Last updated