LogoLogo
⚠️ Outdated documentationGo to latestHomeAPI
SDK 1.3
SDK 1.3
  • Welcome
  • Overview
    • Features
    • Roadmap
  • Getting started
    • Get the Unity SDK
    • Setup a project
      • Scene setup
      • Prefab setup
      • Sample connection UIs
      • Local development
        • Local testing using Builds
        • Local testing via Unity's Multiplayer Play Mode (MPPM)
        • Local testing via ParrelSync
      • Test in the cloud
        • Deploy a Replication Server
        • Share builds
    • Video tutorials
    • Samples and tutorials
      • Package samples
      • First Steps tutorial
        • 1. Basic syncing
          • 1.2. Animation parameters
          • 1.3. Sending commands
        • 2. Physics / Authority transfer
        • 3. Areas of interest
        • 4. Parenting entities
        • 5. Complex hierarchies
        • 6. Persistence
      • Campfire project
        • Game mechanics
        • Leveraging object pooling
        • Remote interactions: Chairs
        • Remote interactions: Trees
        • A unique object with complex state
        • Custom instantiation and destruction
        • Running a server-side NPC
        • Playing audio and particles
        • A simple text chat
      • Beginner's guide to networking
  • Manual
    • Unity Components
      • CoherenceSync
      • CoherenceBridge
      • CoherenceNode
      • CoherenceLiveQuery
      • CoherenceTagQuery
      • PrefabSyncGroup
      • CoherenceInput
      • Order of execution
    • Networking state changes
      • Supported types
      • Messaging with Commands
      • Syncing child GameObjects
      • Animation
      • CoherenceSync references
      • [Sync] and [Command] Attributes
      • [OnValueSynced] Attribute
      • Creating your own syncable member
      • Custom Component Actions
      • Rigid Bodies
      • Interpolation
    • Authority
      • Authority transfer
      • Server-authoritative setup
    • Lifetime
      • Persistence
      • Uniqueness
      • Example: A global counter
    • Parenting network entities
      • Direct children CoherenceSyncs
      • Deeply-nested CoherenceSyncs
      • Nesting Prefabs at Edit time
    • Asset management
      • Instantiate via
      • Load via
      • Instantiating from CoherenceSyncConfig
    • Scene management
    • Baking (code generation)
    • Replication Server
      • Rooms and Worlds
      • Replication Server API
    • Simulators (Servers)
      • Scripting: Client vs Simulator
      • Run local Simulators
      • World Simulators
      • Room Simulators
      • Simulator slugs
      • Multi-Room Simulators
      • Build and Deploy
      • Command-line arguments
    • Client Connections
    • Optimization
      • Areas of Interest
      • Level of Detail (LOD)
      • Profiling
      • Simulation Frequency
    • Project Settings
    • Advanced topics
      • Big worlds
        • World Origin Shifting
        • Load balancing
      • Competitive games
        • Simulation Frame
        • Determinism, Prediction and Rollback
      • Team workflows
        • Version Control integration
        • Continuous Integration
      • Schema explained
        • Specification
        • Field settings
        • Archetypes
      • Code Stripping
      • Command-line interface tools
      • Single-player gameplay
    • Scripting API
  • Hosting
    • Choosing where to host
    • coherence Cloud
      • Online Dashboard
      • Manage Worlds
      • Configure Rooms
      • Lobbies
      • Game Services
        • Account
        • Key-Value Store
      • coherence Cloud APIs
        • Worlds API
        • Rooms API
        • Lobbies API
        • Game Services
          • Authentication Service (Player Accounts)
          • Key-value store
    • Peer-to-peer
      • Implementing Client hosting
  • Support
    • Release notes
    • Glossary
    • Unreal Engine support
    • WebGL support
    • ECS / DOTS support
    • Known issues and troubleshooting
    • Upgrade guide
      • Upgrade 1.2 -> 1.3
      • Upgrade 1.1 -> 1.2
      • Upgrade 1.0 -> 1.1
      • Upgrade 0.10 -> 1.0
      • Upgrade 0.9 -> 0.10
    • Credit cost & pricing
    • Report a bug
Powered by GitBook
On this page
  • How do they work?
  • Setting up Multi-Room Simulators
  • Manually setting up Multi-Room Simulators
  • In-editor debugging
  • Limitations
  • Allowing Multi-Room Simulators in the Online Dashboard

Was this helpful?

Export as PDF
  1. Manual
  2. Simulators (Servers)

Multi-Room Simulators

Simulate multiple Rooms at the same time, within one Unity instance

Was this helpful?

Multi-Room Simulators are Room Simulators which are able to simulate multiple game rooms at the same time - one sim to rule them all!

In order to achieve this, the game code should be defensive on which room it is affecting. Game state should be kept per Room, meaning game managers, singletons (static data), etc. need to account for this.

Each Room is held in a different scene. So for every Room created, the Multi-Room Simulator should open a connection to it, hence loading additively a scene and stablishing a Simulator connection (via Bridge).

How do they work?

By using Multi-Room Simulators, the coherence Cloud is able to instruct your Simulator which room to join and start simulating.

This communication happens via HTTP. An HTTP server is started by your game build when the MultiRoomSimulator component is active. This component listens to HTTP requests made by the coherence __ Online Dashboard.

For offline local development, you can use a MultiRoomSimulatorLocalForwarder component on your clients, which will create HTTP requests against your local simulator upon client connection, like joining a room.

For local development, enable the Local Development Mode flag in the .

Once the MultiRoomSimulator receives a request to join a room, it spawns a CoherenceSceneLoader that will be in charge of loading additively the scene specified.

Setting up Multi-Room Simulators

The quickest way to get Multi-Room Simulators set up is by using the provided wizard.

It will take you through the GameObjects and Components needed to make it happen.

Manually setting up Multi-Room Simulators

Here's a quick overview video of the setup:

These are the pieces needed for Multi-Room Simulators to work:

  • Simulators

    • In the initialization scene (splash, init, menu, ...)

      • MultiRoomSimulator — listens to join room requests and delegates scene loading (by instantiating CoherenceSceneLoaders)

  • Clients

    • (Only for local development) In the scene where you connect to a Room (where you have the Sample UI or your custom connection logic)

      • MultiRoomSimulatorLocalForwarder — requests the local MultiRoomSimulator to join rooms when the Client connects.

  • Independently

    • In the scene where the networked game logic is (game, Room, main, ...)

      • Bridge — handles the connection

      • LiveQuery — filters Entities by distance

      • CoherenceScene — when the scene is loaded via CoherenceSceneLoader, it will try to connect using the data given by it. It attaches to the Bridge, creates a connection, and handles auto reconnection. If a scene loaded through CoherenceSceneLoader doesn't have a CoherenceScene on it, one will be created on the fly.

There are two components that can help you fork Client and Simulator logic, for example, by enabling or disabling the MultiRoomSimulator component depending on whether it's a Simulator or a Client build. These are optional but can come in handy.

  • SimulatorEventHandler — events on the build type (Client/Simulator).

  • ConnectionEventHandler — events on the connection stablished by the Bridge associated with that Scene.

In-editor debugging

It is possible to visualize each individual Room the Multi-Room Simulator is working on. By default, Simulator connections to Rooms are hidden, as shown in the image above. You can toggle the visibility per scene by clicking the Eye icon. You can also change the default visibility of the loaded scene (defaults to hidden) on the CoherenceScene component:

Limitations

Working with Multi-Room Simulators needs your logic to be constrained to the scene. Methods like FindObjectsOfType will return objects in all scenes — you could affect other game sessions!

Check out Coherence.Toolkit.SceneUtils for alternative APIs to FindObjectsOfType that work per scene.

Also, Coherence.Toolkit.ActiveSceneScope can help make sure instantiation happens where you want it to be.

This is also true for static members, e.g. singletons. When using Multi-Room Simulators, there need to be as many isolated instances of your managers as there are open simulated rooms.

For example, if you were to access your Game Manager through GameManager.instance, now you'll need a per-scene API like GameManager.GetInstance(scene).

There may be third-party or Unity-provided features that can't be accessed per scene, and that affect the whole game.

Loading operations, garbage collections, frame-rate spikes... all these will affect performance on other sessions, since everything is running within the same game instance.

Allowing Multi-Room Simulators in the Online Dashboard

By default, scenes will have their . coherence ticks the physics scene on the CoherenceScene component, which the target scene to be loaded should include.

Multi-Room Simulators are still . You need to enable Simulators for Rooms and enable Multi-Room Simulators in the coherence Online Dashboard, as shown here:

physics scene
Room Simulators
project settings
MultiRoomSimulator inspector
Wizard at coherence > Simulator > Multi-Room Simulator Wizard
SimulatorEventHandler
ConnectionEventHandler
Hierarchy view with additional coherence controls
CoherenceSync inspector
Scene visibility options, when this scene is loaded through CoherenceSceneLoader (hence via MultiRoomSimulator)