githubEdit

Networking Events

Complete reference for networking lifecycle events.

The following events are available to listen to in your components. They describe common network events that you might want to react to, such as users joining or leaving rooms, room state changes, and connection events.

Room Events

Events related to room lifecycle - joining, leaving, and state updates.

JoinedRoom

Fired when you (the local user) have joined a networked room.

this.context.beginListen(RoomEvents.JoinedRoom, ({room, viewId, allowEditing, inRoom}) => {
    console.log("Joined room:", room);
    console.log("View ID:", viewId);
    console.log("Can edit:", allowEditing);
    console.log("Users in room:", inRoom);
});

Event Data:

  • room (string) - Room ID

  • viewId (string) - Your unique view identifier

  • allowEditing (boolean) - Whether you can modify room state

  • inRoom (string[]) - Array of connection IDs currently in the room

Use Cases:

  • Initialize networking-dependent components

  • Show "Connected" UI state

  • Load user-specific data

  • Set up presence indicators


LeftRoom

Fired when you (the local user) have left a networked room.

Event Data:

  • room (string) - Room ID you just left

Use Cases:

  • Clean up networking resources

  • Show "Disconnected" UI state

  • Reset scene state if needed

  • Remove presence indicators


UserJoinedRoom

Fired when another user has joined your networked room.

Event Data:

  • userId (string) - Connection ID of the user who joined

Use Cases:

  • Spawn player avatars

  • Show join notifications

  • Update player count UI

  • Initialize player-specific objects


UserLeftRoom

Fired when another user has left your networked room.

Event Data:

  • userId (string) - Connection ID of the user who left

Use Cases:

  • Remove player avatars

  • Show leave notifications

  • Update player count UI

  • Clean up player-specific objects


RoomStateSent

Fired after all current room state has been sent to the client. This happens after you join a room.

Event Data: None

Use Cases:

  • Know when initial synchronization is complete

  • Start game logic after state is loaded

  • Show "Ready" state to user

  • Trigger animations or effects after sync


::: tip API Documentation See all Room Events in the API docs →arrow-up-right :::

Ownership Events

Events related to object ownership - requesting, gaining, and losing ownership of objects.

Request Ownership

Send a request to gain ownership of an object:

Request Has Owner

Check if an object currently has an owner:

Remove Ownership

Release ownership of an object:

Gained Ownership

Fired when you gain ownership of an object:

Lost Ownership

Fired when you lose ownership of an object:

::: tip API Documentation See all Ownership Events in the API docs →arrow-up-right :::

Connection Events

Events related to the WebSocket connection itself.

Connection Start Info

Fired when the WebSocket connection is established:

Event Data:

  • id (string) - Your unique connection ID

Use Cases:

  • Store your connection ID

  • Initialize connection-dependent features

  • Show "Connecting..." → "Connected" transition


::: tip API Documentation See all Connection Events in the API docs →arrow-up-right :::

Utility Events

Built-in events for common networking operations.

New Instance Created

Fired when syncInstantiate() creates a new instance:

Event Data:

  • guid (string) - GUID of the new instance

  • originalGuid (string) - GUID of the original object

  • seed (number) - Random seed for the instance

  • visible (boolean) - Initial visibility

  • parent (string) - Parent object GUID

  • position, rotation, scale - Transform data

  • deleteStateOnDisconnect (boolean) - Whether to delete on disconnect


Instance Destroyed

Fired when syncDestroy() destroys an instance:

Event Data:

  • guid (string) - GUID of the destroyed instance

  • dontSave (boolean) - Whether to persist the destruction


Ping / Pong

Connection keepalive messages sent automatically:

These are handled automatically - you typically don't need to listen for them.


Delete State / Delete All State

Delete state from the room:

Usage Patterns

Initialize After Joining

Wait for room join before setting up networking:

Track Connected Players

Maintain a list of connected users:

Request Ownership Before Modifying

Always check ownership before modifying networked objects:

Next Steps

Learn more:

API Reference:

Last updated