LogoLogo
⚠️ Outdated documentationGo to LatestHomeAPI
SDK 0.8
SDK 0.8
  • Welcome
  • Overview
    • What is coherence?
    • How does coherence work?
    • Features and Roadmap
    • Rooms and Worlds
    • Requirements
  • Get Started
    • Install coherence
    • Scene setup
    • Prefab setup
    • Baking and code generation
    • Build and run
    • Create a free account
    • Deploy replication server
    • Share builds
  • Authority and communication
    • How authority works
    • Authority transfer
    • Commands
    • Client connections
    • Input Queues
    • Input prediction and rollback
    • Animations
    • Value sync callbacks
  • 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
    • CoherenceNode
  • Simulators
    • Overview
    • Client vs. simulator logic
    • Build and deploy
    • Simulator load balancing
    • Room Simulators
    • Multi-Room Simulators (Advanced)
    • World Simulators
    • Simulator Slugs
    • Testing Simulators Locally
  • 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. Team based
      • 8. Connected Entities
  • Game Services
    • Game account
    • Key-value store
    • Matchmaking
  • Developer Portal
    • Overview
    • Dashboard
    • Enabling Game Services
    • Configure Rooms
    • Manage Worlds
  • API reference
    • Network SDK
      • CoherenceSync
      • MonoBridge
      • LiveQuery
      • Archetype
      • Sample UI
      • Settings Window
      • Custom Bindings (Advanced)
      • PlayResolver
      • Rooms
      • Worlds
    • Cloud API
      • API tokens and keys
      • 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
    • Simulator CLI arguments
    • 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
  • How they work?
  • Setting up Multi-Room Simulators
  • Manually setting up Multi-Room Simulators
  • In-editor Debugging
  • Limitations
  • Allowing Multi-Room Simulators in the Developer Portal

Was this helpful?

Export as PDF
  1. Simulators

Multi-Room Simulators (Advanced)

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

Last updated 3 years ago

Was this helpful?

Multi-Room Simulators are Room Simulators which are able to simulate different game rooms at the same time. One game build 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 MonoBridge).

How they work?

By using Multi-Room Simulators, the coherence Developer Portal 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 Developer Portal.

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 i.e. 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 drive you through the GameObjects and Components needed to make it happen.

Some steps are not strictly necessary. For example, you don't need a Sample UI for Multi-Room Simulators to happen. However, if you do use the Sample UI, we help you make sure you have it set up properly.

Manually setting up Multi-Room Simulators

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, ...)

      • MonoBridge — 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 MonoBridge, 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 MonoBridge associated with that scene.

In-editor Debugging

It's 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!

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 might be third-party or Unity-provided features that can't be accessed per scene, and affect the whole game.

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

Allowing Multi-Room Simulators in the Developer Portal

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 Developer Portal, 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)