State Sync
State synchronization is the process by which the server broadcasts the authoritative world state to connected clients on each tick.
How it works
- Server tick — On each fixed tick (default 30/s), the server steps the physics world and updates all entities
- Serialization — Each entity's state is serialized via
serialize()(fromGameObject) - Distance filtering — Only entities within
getStateSyncDistance()of a given client are included in that client's state packet - Broadcast — The filtered state is sent to each client over the WebRTC socket
- Client apply — The client calls
updateFromNetwork(data)on each matching local entity, and creates unknown ones with the NetworkedEntityFactory
What is synced
- Scene objects are map data every client loads itself, so they are not sent, unless they are networked entities (
NetworkedGameObject). - Clients running the level editor are no players: they get every synced entity in the world, regardless of distance.
- When a player disconnects, the server flags it with
garbageCollect; the world destroys it on the next tick, and nearby clients getSV_REMOVE_ENTITY.
Client-side prediction
Clients apply their own inputs right away and send them with NetworkManager.sendCommand(), which gives each one a sequence id. The server applies them in order and sends each player's lastProcessedSequenceId back in the state. The client drops the acknowledged inputs with dropCommandsAtSequenceId() and corrects its player from the server's state. See NetworkManager.
Distance-based visibility
The server only sends state for entities within a configurable radius of each connected client. This reduces bandwidth for large worlds.
class MyServer extends Server {
getStateSyncDistance(): number {
return 150 // Only sync entities within 150 units
}
}
Bandwidth tracking
Monitor sent and received bandwidth with the built-in tracker:
server.bandwidthTracker // Access bandwidth stats
The dashboard shows it live, per second.
State packet format
Every SV_STATE is stamped by the server, so clients and tools can tell states apart:
| Field | Description |
|---|---|
tick | Number of the server tick the state was taken in. Goes up by one per tick, so a gap means a lost packet |
serverTime | Epoch ms on the server when the state was taken |
ack | Sequence id of the receiver's last input the server processed before this state. null for a client without a player, like the editor |
entities | Each entity's serialize() output: id, position, rotation, state hash and any custom fields |
The client keeps the stamps of the last state in NetworkManager.serverView.
Entities with garbageCollect === true are omitted from state packets and the client is notified to remove them.
Network debugging
In development both sides record their traffic: every message through the game socket, the engine's and your own, with its size, and events such as:
| Event | Side | |
|---|---|---|
connect / disconnect | both | |
dropped | both | The transport dropped a message |
sync_enter / sync_leave | server | Entities coming into or leaving a player's sync distance |
state_gap | client | State updates that never arrived |
state_out_of_order | client | A state that arrived after a newer one |
Each side keeps its last 2000 records, and 8 MB of their payloads. The server records when NODE_ENV is not production (server.net); a tab records while the dev bridge or the editor runs (network.net, or turn it on with network.net.enabled = true). Nothing is recorded, and the socket is left untouched, in a production build.
server.syncSnapshot() tells who is sent what: each player's tracked entities and last state update, and by how many players each entity is tracked.
Look at it in:
- the Network tab of the dashboard: state sync per player, traffic by message and every packet with its payload;
- the Network panel of the editor: packet list, timeline, state sync, and server ghosts and sync radius rings in the viewport;
- the network tools of the MCP server, for an AI assistant.
Tick rate
The server tick rate controls how frequently state is sent. Default is 30 ticks/second, matching common game server conventions (sv_tickrate).
const game = BaseGame.instance()
game.tickRate // 30 (default)
To test how your game feels on a bad connection, enable the server's latency simulation.
A higher tick rate gives smoother interpolation but increases bandwidth and CPU usage.