For the complete documentation index, see llms.txt. This page is also available as Markdown.

Multiplayer (beta)

Realtime room multiplayer on Playgama servers. Players meet in a room — by a code, through quick match or from a room list — and exchange messages. One player of the room is the host: the game on the host's device decides what happens, the other players send it their actions and repeat what it sends back. The server relays messages and passes the host role to another player when the host leaves or drops.

How to make a match start in seconds when few players are online, with bots in the empty seats: Multiplayer guide.

Implementation order

  1. Required — Add the SaaS public token to the config (see Configuration).

  2. Required — Check isSupported before showing online modes.

  3. Required — Put the player into a room: create one, join by code or use quick match.

  4. Required — Subscribe to players and message events, and to room left to handle a lost connection.

  5. Recommended — Let players invite friends with inviteToRoom() and open the room from the invite with launchRoomId.

  6. Optional — Let Bridge copy the host's game world to the other players and keep it when the host changes with syncState.

Configuration

Get the public token from your game's card in the developer dashboard, under Bridge SaaS → Multiplayer, and add it to the saas section of the config:

playgama-bridge-config.json
{
  ...
  "saas": {
    "publicToken": "<YOUR_APP_PUBLIC_TOKEN>"
  }
}

Without the token isSupported is false. The multiplayer.apiBase option overrides the server address; leave it out in production builds.

How it works

  • Rooms. A room has a code of 8 characters (for example K7M4X9TR) that other players type or open from an invite link, a maximum number of players (4 by default), an open/closed flag and a visibility flag. Only visible rooms take part in quick match and the room list; a room created with createRoom() is hidden by default — friends join it by code.

  • Filter and properties. A room has two sets of flat values (string, number or boolean). The filter is the room's matchmaking key, for example { mode: 'duel', version: 3 }: it is set once when the room is created and never changes, and quick match and the room list compare it as a whole, types included (2 and '2' differ, { mode: 'duel' } does not match { mode: 'duel', version: 3 }). The properties are the room's data, for example { map: 'forest', round: 2 }: the game changes them at any time and every player sees them, but matchmaking ignores them. A created room also gets its filter values in its properties, so players can read them.

  • Regions. Each player is served by one region (Europe, Americas or Asia). Quick match and the room list see only the rooms of the player's region; a room code works from any region.

  • Host. The server picks the host: the player who created the room, then — when the host leaves or drops — another player. Keep the authoritative game state on the host and send it to the others, yourself or with Sync State; check isHost after every host changed event.

  • Messages. A message has a type (string) and data. Messages from one player arrive in the order they were sent. Players who are reconnecting do not receive messages sent meanwhile.

  • Reconnects. When the connection drops, Bridge reconnects by itself and the player keeps the seat; the state is reconnecting meanwhile. If reconnecting fails, the player leaves the room with the connection_lost reason.

Is Supported

Use the Is Multiplayer Supported condition.

Use the Is Multiplayer Supported condition.

The module is Bridge.mp: every Godot node already has a built-in multiplayer property.

State

disconnected, connecting, connected or reconnecting.

Use the Multiplayer State is condition, the On Multiplayer State Changed trigger and the PlaygamaBridge.MultiplayerState expression.

Use the Multiplayer Is State condition, the On Multiplayer State Changed condition and the PlaygamaBridge::MultiplayerState() expression.

Create Room

Creates a room and enters it as the host. Returns the room code.

Option
Type
Default
Description

maxPlayers

number

4

Room size, from 2 to 16 players.

isVisible

boolean

false

Visible rooms take part in quick match and the room list.

isOpen

boolean

true

Closed rooms do not accept new players.

filter

flat object

—

Matchmaking key, up to 16 values; see Filter and properties. A visible room is found by quick match and the filtered room list only with the same filter.

properties

flat object

—

Room properties.

playerProperties

flat object

—

Properties of the local player.

syncState

boolean or object

—

true or { updatesPerSecond }: synchronizes the game world, see Sync State.

Add the options with Add Action Parameter (dotted keys go into nested options), call Multiplayer Create Room, then handle the On Multiplayer Create Room Completed trigger. The room code is in PlaygamaBridge.MultiplayerRoomId, the error code in PlaygamaBridge.MultiplayerLastErrorCode.

Copy This Example

Add the options with Add Action Parameter (dotted paths go into nested options), call Multiplayer Create Room, then handle the On Multiplayer Create Room Completed condition. The room code is in PlaygamaBridge::MultiplayerRoomId(), the error code in PlaygamaBridge::MultiplayerLastError().

Copy This Example

Join Room

Enters a room by its code. Options: playerProperties, syncState (see Sync State).

Call Multiplayer Join Room with the code, then handle On Multiplayer Join Room Completed and check Is Last Action Completed Successfully.

Call Multiplayer Join Room with the code, then handle On Multiplayer Join Room Completed and check Is Last Action Completed Successfully.

Join Or Create Room

Quick match: enters a visible open room with a free seat, the same maxPlayers and exactly the same filter, or creates a visible room when none fits. Returns the room code.

Option
Type
Description

maxPlayers

number

Players meet only in rooms of the same size.

filter

flat object

Matchmaking key, up to 16 values: players meet only in rooms with exactly the same filter. No filter matches only rooms without one.

properties

flat object

Extra properties of a created room.

playerProperties

flat object

syncState

boolean or object

Put the game version or mode into filter so that incompatible builds never meet.

Add maxPlayers and filter.mode with Add Action Parameter, call Multiplayer Join Or Create Room, then handle On Multiplayer Join Or Create Room Completed.

Add maxPlayers and filter.mode with Add Action Parameter, call Multiplayer Join Or Create Room, then handle On Multiplayer Join Or Create Room Completed.

Get Rooms

Lists visible open rooms with a free seat in the player's region. Options: filter (only rooms created with exactly this filter; all rooms when left out), maxPlayers, limit. Each room: id, type, maxPlayers, playerCount, filter, properties.

Add filter.mode and limit with Add Action Parameter, call Multiplayer Get Rooms, then in On Multiplayer Get Rooms Completed loop from 0 to PlaygamaBridge.MultiplayerRoomListCount - 1 and read MultiplayerRoomListId(index), MultiplayerRoomListPlayerCount(index), MultiplayerRoomListMaxPlayers(index), MultiplayerRoomListProperty(index, "mode").

Add filter.mode and limit with Add Action Parameter, call Multiplayer Get Rooms, then in On Multiplayer Get Rooms Completed repeat PlaygamaBridge::MultiplayerRoomListCount() times and read MultiplayerRoomListId(index), MultiplayerRoomListPlayerCount(index), MultiplayerRoomListMaxPlayers(index), MultiplayerRoomListProperty(index, "mode").

Invite To Room

Asks the platform to share a link to the current room; a player who opens it gets the room code in launchRoomId. Check isInviteSupported first; where it is false, show the room code instead. Options: text, image.

Check Is Multiplayer Invite Supported, call Multiplayer Invite To Room (text from Add Action Parameter), then handle On Multiplayer Invite To Room Completed.

Check Is Multiplayer Invite Supported, call Multiplayer Invite To Room (text from Add Action Parameter), then handle On Multiplayer Invite To Room Completed.

Launch Room ID

The room code from the invite link the game was opened with, or empty. Join that room right after initialization. It is cleared once the player enters any room.

Use the Has Multiplayer Launch Room Id condition and the PlaygamaBridge.MultiplayerLaunchRoomId expression.

Use the PlaygamaBridge::MultiplayerLaunchRoomId() expression.

Leave Room

leaveRoom() takes the player out of the room. The room left event comes with a reason: left (the game called leaveRoom()), connection_lost (reconnecting failed) or room_closed (the server closed the room).

Call Multiplayer Leave Room. Handle On Multiplayer Room Left; the reason is in PlaygamaBridge.MultiplayerLastRoomLeftReason or the Multiplayer Room Left Reason is condition.

Call Multiplayer Leave Room. Handle On Multiplayer Room Left; the reason is in PlaygamaBridge::MultiplayerRoomLeftReason().

Room

roomId is the room code. room holds id, maxPlayers, isOpen, isVisible, hostId and properties; the room updated event fires when any of them changes. The host can change the room:

  • setRoomOpen(isOpen) — closes the room for new players (for example when the match starts) or opens it again.

  • setRoomVisible(isVisible) — shows or hides the room in quick match and the room list.

  • setRoomProperties(properties) — keys are merged into the room properties.

Expressions: MultiplayerRoomId, MultiplayerRoomMaxPlayers, MultiplayerRoomProperty("map"). Actions: Multiplayer Set Room Open, Multiplayer Set Room Visible, Multiplayer Set Room Properties (the properties come from Add Action Parameter). Trigger: On Multiplayer Room Updated.

Expressions: MultiplayerRoomId(), MultiplayerRoomMaxPlayers(), MultiplayerRoomProperty("map"). Actions: Multiplayer Set Room Open, Multiplayer Set Room Visible, Multiplayer Set Room Properties (the properties come from Add Action Parameter). Condition: On Multiplayer Room Updated.

Players

players lists the connected players: id, name, isHost, isConnected, properties. playerId is the local player, hostId the host, isHost tells whether the local player is the host. Events: player joined, player left, player updated (properties or connection changed) and host changed (the new host, or none). Each player can change its own properties with setPlayerProperties(properties); keys are merged.

Loop from 0 to MultiplayerRoomPlayersCount - 1 and read MultiplayerRoomPlayerId(index), MultiplayerRoomPlayerName(index), MultiplayerRoomPlayerIsHost(index), MultiplayerRoomPlayerIsConnected(index), MultiplayerRoomPlayerProperty(index, "ready"). MultiplayerPlayerId and MultiplayerHostId are the local player and the host, Is Multiplayer Host checks the role.

Triggers On Multiplayer Player Joined, On Multiplayer Player Left, On Multiplayer Player Updated and On Multiplayer Host Changed fill MultiplayerLastEventPlayerId, MultiplayerLastEventPlayerName and MultiplayerLastEventPlayerProperty("ready"). Multiplayer Set Player Properties takes the properties from Add Action Parameter.

Repeat MultiplayerPlayersCount() times and read MultiplayerRoomPlayerId(index), MultiplayerRoomPlayerName(index), MultiplayerRoomPlayerProperty(index, "ready"); the MultiplayerRoomPlayerIsHost and MultiplayerRoomPlayerIsConnected conditions take the index. MultiplayerPlayerId() and MultiplayerHostId() are the local player and the host, Multiplayer Is Host checks the role.

Conditions On Multiplayer Player Joined, On Multiplayer Player Left, On Multiplayer Player Updated and On Multiplayer Host Changed fill MultiplayerEventPlayerId(), MultiplayerEventPlayerName() and MultiplayerEventPlayerProperty("ready"). Multiplayer Set Player Properties takes the properties from Add Action Parameter.

Send Messages

send(type, data, { to }) sends a message. to is others (default), all (the sender too), host, a player id or a list of player ids.

Add the data with Add Action Parameter, then call Multiplayer Send Message with the type and the target (Others, All, Host or Player (by ID) with the player id).

Copy This Example

Add the data with Add Action Parameter, then call Multiplayer Send with the type and the target: all, others (empty), host or a player id.

Copy This Example

Receive Messages

The message received event gives type, data and from (the sender's player id).

Messages are delivered once per frame, from Update.

Handle On Multiplayer Message Received and read MultiplayerLastMessageType, MultiplayerLastMessageFrom and MultiplayerLastMessageDataValue("x"). The trigger fires once per message.

Handle On Multiplayer Message Received and read MultiplayerLastMessageType(), MultiplayerLastMessageFrom() and MultiplayerLastMessageDataValue("x"). Messages are delivered one per frame in the order they arrived.

Sync State

Optional. Bridge keeps the game world on the host and copies it to the other players. Every player enters the room with the syncState option: true, or { updatesPerSecond: 5 } for fewer snapshots a second (from 1 to 10, 10 by default). The host sets its world whenever it changes, and up to updatesPerSecond times a second Bridge sends the latest one to the other players: they get it with the sync state received event. The server keeps the last world: when the host leaves or drops, the new host gets it with the same event and the game goes on from the same point. The world is passed in the same format as message data.

Without syncState the game sends its state with messages itself, and a new host has only what its own device knows.

Instead of setSyncState() and the event, syncState can take callbacks: Bridge takes the world from getState() on the host and passes received worlds to applyState(). Both must be synchronous and may run before the entry promise resolves; do not check isHost in getState(), the first snapshot is taken before the host role is confirmed.

The world is a flat dictionary, like message data: nested values arrive as JSON strings.

Turn the sync on when entering a room: before Multiplayer Create Room, Multiplayer Join Room or Multiplayer Join Or Create Room add Add Bool Action Parameter with the key syncState checked, or Add Action Parameter with the key syncState.updatesPerSecond and a number from 1 to 10.

Add the world with Add Action Parameter, then call Multiplayer Set Sync State; each call replaces the whole world, so add every key each time. Handle On Multiplayer Sync State Received and read MultiplayerSyncStateValue("score"): it returns the last world set or received, on the host too.

Turn the sync on when entering a room: before Multiplayer Create Room, Multiplayer Join Room or Multiplayer Join Or Create Room add syncState with Add Bool Action Parameter, or syncState.updatesPerSecond from 1 to 10 with Add Action Parameter.

Add the world with Add Action Parameter, then call Multiplayer Set Sync State; each call replaces the whole world. Handle On Multiplayer Sync State Received (true at most once per frame, with the latest world) and read MultiplayerSyncStateValue("score"): it returns the last world set or received, on the host too.

Bridge.mp.sync_state is the last world set or received.

  • Every player enters the room with syncState, on every room entry. When a player without it becomes the host, its empty world replaces the game.

  • Change the world only on the host and set it again after every change: Bridge keeps a copy. The other players send their actions to the host with messages; the next snapshot overwrites their own changes.

  • Set the starting world and subscribe to the event before entering the room: the first snapshot is taken right after entering, and a new host may get the world before the entry completes. The world is cleared when the player leaves the room.

  • Each snapshot is the whole world, not a change. Snapshots and messages share one limit of 64 KB a second per player: when the world does not fit, Bridge sends snapshots less often and skips the ones in between. Keep the world small; fast-paced games should send their updates with messages.

  • A world that is not a JSON object is not set, and a world larger than 64 KB stops synchronization for this player: it can no longer be the host. Bridge logs a warning.

Errors

Failed requests report a code: error.code in Plain JS and Cocos Creator, lastError in Unity, last_error in Godot, the failure data in GameMaker and Defold, MultiplayerLastErrorCode in Construct 3 and MultiplayerLastError() in GDevelop.

Code
Meaning

MULTIPLAYER_NOT_SUPPORTED

No public token, or the platform does not support multiplayer.

MULTIPLAYER_ALREADY_IN_ROOM

The player is already in a room or entering one.

MULTIPLAYER_NOT_IN_ROOM

The call needs a room.

MULTIPLAYER_ROOM_NOT_FOUND

No room with this code.

MULTIPLAYER_ROOM_FULL

The room has no free seat.

MULTIPLAYER_ROOM_CLOSED

The room does not accept new players.

MULTIPLAYER_CONNECTION_FAILED

The server could not be reached.

Last updated