menu_bookDocumentation

s&box SceneNetworkSystem: Scene Loading and Snapshot Protocol

calendar_today May 4, 2026 schedule ~1 min read person patrickjr verified 50

s&box SceneNetworkSystem: Scene Loading and Snapshot Protocol

SceneNetworkSystem is the core networking system that manages scene loading, object spawning, and snapshot synchronization between host and clients.

Scene Load Protocol

When the host changes scenes, the following sequence occurs:

CODE
Host:
  1. LoadSceneBroadcast() → sends LoadSceneBeginMsg to all connected clients
  2. Waits for clients to request snapshot

Client:
  1. Receives LoadSceneBeginMsg → destroys current scene, mounts VPKs
  2. Sends LoadSceneRequestSnapshotMsg to host
  3. Receives LoadSceneSnapshotMsg → deserializes scene + network objects
  4. Sends SceneLoadedMsg to host
  5. OnClientInitialize() fires

Host:
  5. Receives SceneLoadedMsg → sets connection.State = Connected
  6. Calls INetworkListener.OnActive(client)

Snapshot Contents

The snapshot sent to joining clients includes:


Batch Spawning

Use NetworkSpawnBatch() to group multiple spawns into one message:

CSHARP
using (SceneNetworkSystem.Instance.NetworkSpawnBatch())
{
    // All spawns here are batched into one ObjectCreateBatchMsg
    prefab1.NetworkSpawn(owner);
    prefab2.NetworkSpawn(owner);
    prefab3.NetworkSpawn(owner);
}

This ensures child network objects maintain their references when received on the other side.

Suppressing Messages

CSHARP
// Suppress spawn messages (objects created here won't be networked)
using (SceneNetworkSystem.SuppressSpawnMessages())
{
    var go = new GameObject(); // not sent to clients
}

// Suppress destroy messages
using (SceneNetworkSystem.SuppressDestroyMessages())
{
    go.Destroy(); // not sent to clients
}

Connection States

Connections progress through states during scene loading:

  1. Connected — initial connection

  2. MountVPKs — mounting map VPKs

  3. Snapshot — receiving scene snapshot

  4. Connected — fully loaded and active

INetworkListener.AcceptConnection

CSHARP
// Called on host to accept/reject connections
public bool AcceptConnection(Connection c, ref string reason)
{
    if (PlayerCount >= MaxPlayers)
    {
        reason = "Server is full";
        return false;
    }
    return true;
}

If ANY INetworkListener returns false, the connection is rejected.

Was this helpful?