Connection & Matchmaking

Initialization

GDScript

# From Project Settings (recommended)
FusionClient.initialize_from_settings()

# Or with explicit parameters
FusionClient.initialize("your-app-id", "1.0")

Connecting

Use connect_to_server() to initialize and connect in one call. All parameters are optional — empty values are filled from Project Settings:

GDScript

# Simplest: everything from Project Settings
FusionClient.connect_to_server()

# With a specific user ID
FusionClient.connect_to_server("player_123")

# With a specific region (forces Cloud mode)
FusionClient.connect_to_server("player_123", "us")

Connection mode (Cloud vs Local) is determined by Project Settings > Fusion > Connection > Mode unless a region is explicitly provided.

Project Settings — Fusion
Project Settings — Fusion

Connecting and Joining

GDScript

FusionClient.connect_to_server("player_123", "us")

# Wait for connection, then join
FusionClient.connected_to_server.connect(func():
    FusionClient.join_or_create_room("lobby")
)

For local development, set fusion/connection/mode to Local in Project Settings.

Room Operations

GDScript

# Create a new room (fails if it already exists)
FusionClient.create_room("my_room", options)

# Join an existing room (empty name = random room)
FusionClient.join_room("my_room", options)

# Join if exists, create if not
FusionClient.join_or_create_room("my_room", options)

# Leave current room (stays connected for re-matchmaking)
FusionClient.leave_room()

The options parameter is an optional Dictionary.
Omit it or pass {} for defaults.

Room Options

Key Type Description
max_players int Maximum players allowed in the room
is_visible bool Whether the room appears in lobby queries
is_open bool Whether the room accepts new players
player_ttl_ms int Milliseconds before an inactive player slot is freed
empty_room_ttl_ms int Milliseconds before an empty room is destroyed
lobby_properties Array[String] Which custom properties are visible in lobby listings
plugins Array[String] Server plugin names to load for this room
any other key bool, int, float, or String Custom room property (e.g. "map", "game_mode")

Connection Status

  • STATUS_DISCONNECTED (0) — not connected
  • STATUS_CONNECTING (1) — establishing connection
  • STATUS_CONNECTED (2) — connected to master server, can join rooms
  • STATUS_JOINING_ROOM (3) — join in progress
  • STATUS_IN_ROOM (4) — in a room, can spawn and sync
  • STATUS_ERROR (5) — connection error

Query methods: is_initialized(), is_connected_to_server(), is_in_room(), is_master_client(), get_local_player_id(), get_network_time().

Signals

  • room_joined — successfully entered a room (safe to spawn objects)
  • room_left — left a room (voluntarily or disconnected)
  • connection_failed(error: String) — connection attempt failed
  • connection_status_changed(status: int) — status changed
  • connected_to_server — connected to master server
  • scene_load_requested(index: int, path: String) — scene change requested (CUSTOM load mode)
  • scene_ready(index: int) — all scene objects registered after load
  • scene_unloaded(index: int, path: String) — scene unloaded

Disconnecting

GDScript

FusionClient.disconnect_from_server()

Example

GDScript

extends Node

func _ready():
    FusionClient.room_joined.connect(_on_room_joined)
    FusionClient.connection_failed.connect(func(e): print("Failed: ", e))

    FusionClient.connect_to_server("player_%d" % randi())

    FusionClient.connected_to_server.connect(func():
        FusionClient.join_or_create_room("lobby", {
            "max_players": 8,
            "is_visible": true,
            "map": "arena",
            "lobby_properties": ["map"],
        })
    )

func _on_room_joined():
    print("In room as player ", FusionClient.get_local_player_id())
Back to top