LogoLogo
HomeOnline DashboardAPIDiscordForums
SDK 0.5.2
SDK 0.5.2
  • Welcome
  • Overview
    • What is coherence?
    • How does coherence work?
    • Features and Roadmap
    • Requirements
  • Get Started
    • Install coherence
    • Scene setup
    • Prefab setup
    • Build and run
    • Baking and code generation
    • Create a free account
    • Deploy replication server
    • Share builds
  • Authority and communication
    • How authority works
    • Authority transfer
    • Commands
    • Client messages
    • Server-side and input queues
    • Animations
  • Persistence
    • Overview
    • Configuring persistence
    • Storage
    • Example – A global counter
  • Optimization
    • Overview
    • Simulation frequency
    • Areas of interest
    • World size
    • Level of detail
    • Interpolation
    • Extrapolation
  • Connected entities
    • Overview
    • Entity references
    • Parent-child relationships
  • Simulators
    • Overview
    • Client vs. simulator logic
    • Build and deploy
    • Simulator load balancing
  • Tutorial project
    • Get the Tutorial Project
    • Start Tutorial
      • 1. Transforms
      • 2. Physics
      • 3. Persistence
      • 4. Animation and Variables
      • 5. AI Navigation
      • 6. Network Commands
      • 7. Network Teams (draft)
  • Game Services
    • Game account
    • Key-value store
    • Matchmaking
  • Developer Portal
    • Overview
    • Dashboard
    • Resource Usage
    • Replicator and Simulator Configuration
    • Enabling Game Services
  • API reference
    • Network SDK
      • CoherenceSync
      • MonoBridge
      • LiveQuery
      • Archetype
      • Sample UI
      • Settings Window
      • Custom Bindings
    • Cloud API
      • API tokens and keys
      • Server discovery
      • Game account
      • Key-value store
      • Matchmaking
    • Replication Server
    • Simulation Server
  • Schema reference
    • Overview
    • Specification
    • Field Settings
    • Archetypes and LOD-ing
  • Resources
    • Downloads
    • SDK Update Guide
    • Video Tutorials
    • Glossary
    • CLI Utilities
    • Helper Scripts
    • Troubleshooting
  • Community
    • Discord
  • Additional information
    • Pricing
    • SLA
    • Unreal Engine support
    • WebGL
    • Peer-to-Peer (P2P)
    • Known Issues
    • Changelog
Powered by GitBook
On this page
  • Creating a simulation server
  • Build and deploy

Was this helpful?

Export as PDF
  1. API reference

Simulation Server

coherence uses the concept of ownership to determine who is responsible for simulating each entity in the game world. By default, each client that connects to the server owns and simulates the entities they create. There are a lot of situations where this setup is not adequate. For example:

  • The number of entities in the game world could be too large to be simulated by the players on their own, especially if there are few players and the world is very large.

  • The game might have an advanced AI that requires a lot of coordination, which makes it hard to split up the work between clients.

  • It's often desirable to have an authoritative object that ensures a single source of truth for certain data. State replication and "eventual correctness" doesn't give us these guarantees.

  • Perhaps the game should run a persistent simulation, even while no one is playing.

With coherence, all of these situations are can be solved using dedicated simulation servers. They behave very much like normal game clients, except they run on their own with no player involved. Usually they also have special code that only they run (and not the clients). It is up to the game developer to create and run these programs somewhere in the cloud, based on the demands of their particular game.

Creating a simulation server

If you have determined that you need one or more simulation servers for your game, there are multiple ways you can go about implementing these. You could create a separate Unity project and write the specific code for the simulation server there (while making sure you use the same schema as your original project).

An easier way is to use your existing Unity project and modify it in a way so that it can be started either as a normal game client, or as a simulation server. This will ensure that you maximize code sharing between clients and servers -- they both do simulation of entities in the same game world after all.

Please note that to build a simulation server, you have to build for the Linux platform.

To determine whether to start a build as client or simulation server, you can use command line arguments:

Reading command line arguments

using System;

class Boot : MonoBehaviour 
{ 
    void Start() 
    { 
        var args = Environment.GetCommandLineArgs(); 
        var isSimulationServer = false;
    
        foreach (var arg in args) {
            if(arg == "--coherence-simulation-server") {
                isSimulationServer = true;
            }
        }
    
        /* do things based on 'isSimulationServer' here... */
    }
}

To pass the command line argument, start the application like this:

$ ./Game --coherence-simulation-server  

To build server build change your build target to be Linux and tick Server build.

Build and deploy

Last updated 3 years ago

Was this helpful?

When building stand-alone builds, Unity also has an option for . This is great for simulation servers since we're not interested in rendering any graphics on these anyway, and you can use it from code. By using headless mode we get a leaner executable that is easier to deploy in the cloud.

Refer to the .

headless mode
Simulator: Build and deploy section