menu_bookDocumentation

INetworkSnapshot: Custom Binary Data in s&box Network Snapshots

calendar_today May 20, 2026 schedule ~1 min read person PatrickJr verified 50

s&box Components can implement Component.INetworkSnapshot to write and read custom binary data during the network snapshot process. When a client joins a server, the snapshot is sent once — this is ideal for large state like voxel worlds or procedural terrain that doesn't fit the [Sync] property model.

Writing Snapshot Data (Host)

The host serializes custom data into the ByteStream sent to joining clients:

CSHARP
public sealed class VoxelWorld : Component, Component.INetworkSnapshot
{
    private byte[] MyVoxelData { get; set; }

    void INetworkSnapshot.WriteSnapshot( ref ByteStream writer )
    {
        writer.Write( MyVoxelData.Length );
        writer.WriteArray( MyVoxelData );
    }
}

Reading Snapshot Data (Client)

The joining client deserializes and can use OnLoad to process asynchronously while the loading screen stays visible:

CSHARP
void INetworkSnapshot.ReadSnapshot( ref ByteStream reader )
{
    var length = reader.Read<int>();
    MyVoxelData = reader.ReadArray<byte>( length ).ToArray();
}

protected override async Task OnLoad()
{
    LoadingScreen.Title = "Building World...";
    await LoadVoxelWorld( MyVoxelData );
}

When to Use

  • Procedural/voxel world data too large for Sync properties
  • Custom map state that must be consistent for all joining clients
  • Any one-time large payload needed at join time (not continuous sync)
Was this helpful?