Multiplayer

Experiences in Spatial are multiplayer by default. On top of the existing multiplayer experience, you can introduce your own custom multiplayer behavior using Network Objects.

Multiplayer features are controlled through the following scripting services:

  • Actor Service - A service that provides access to actors (players) in a server instance.
  • Networking Service - A service to control server instances, get connection status and broadcast custom remote events.
  • Space Content Service - A service that provides access to all objects in a server instance.

Architecture

Spatial's networking system is based on distributed authority topology. his means that final authority over the state of an object is distributed across clients in the space based on object ownership. Largely, the networking architecture in Spatial is similar to Photon Fusion Shared Mode or Netcode for Game Objects Distributed Authority

Relay Server

All traffic between clients connected to a server instance of a space is routed through a relay server. This ensures that clients can communicate with each other even if they are behind firewalls or NATs.

Server and clients

Saved content for a space is stored in the Spatial Cloud. A server instance loads the content when it starts and saves it periodically if it is the host instance. Note that there can only be one host instance at a time.

Persistence

Master Client

A server instance always has a single actor designated as the master client. This can be useful for certain server-like behaviors, for example deciding when to "start" a game or controlling bot behavior.

You can check who is the master client using INetworkingService.isMasterClient or INetworkingService.masterClientActorNumber.

When the master client disconnects, a new master client is automatically chosen by our servers. The INetworkingService.onMasterClientChanged event is triggered when the master client changes.

Vocabulary

  • Client: A single connected user in a space. But keep in mind some experiences allow a user to join as multiple clients.
  • Actor: Same as a client, these words are used interchangeably.
  • Ownership: Responsibility for certain objects or state in a space.
  • State: Overarching term to describe data like transform positions and custom variables. State can be synced or un-synced depending on the context.
  • Server Instance: A session that connects a group of clients together. Each space may have multiple server instances.
  • Remote Event: A custom message sent to other clients in a server instance. Also commonly referred to as Remote Procedure Calls (RPCs).