Skip to content
Work in progress. These docs describe Spawnite at launch, and some parts are still being built.

Networking

In a multiplayer game, the room decides what happens. The room is the server that runs the game’s world, and the platform hosts it. Each player’s client, the game running in that player’s browser, sends the room the player’s input and draws the world the room streams back.

A round trip to the room takes 30 to 300 ms, and a character that waits that long to answer a key feels broken. So the client predicts the player’s own character: it runs the game’s rules for that character at once, a few ticks ahead of the room, with the same code the room runs. The room runs the same input when its own clock reaches that tick. When the two agree, which is the usual case, nothing happens. When they disagree, the client takes the room’s values for that tick and re-runs the ticks since. Whatever changes another player, the world or the score is never predicted: the room decides it, and every client shows the room’s result.

sequenceDiagram
    participant C as The player's client, a few ticks ahead
    participant R as Room
    C->>C: the player presses Dash: the dash shows on the next step
    C->>R: the dash command, naming the tick it is for
    R->>R: runs the same rule on that tick
    R-->>C: its result for that tick
    alt the room agrees
        C->>C: nothing changes
    else the room disagrees
        C->>C: takes the room's result and re-runs its ticks since
    end

These words mean one thing each across the networking pages:

Word Meaning The closest term elsewhere
Room The server process that runs one game world. The platform hosts it. Dedicated server, authority
Client The game running in one player’s browser. Other pages of these docs call it the player’s page. Owning client, autonomous proxy
Character The entity a player controls. The room spawns it as the player joins. Player character, pawn
Tick One step of the world: one run of every system. The room runs 60 a second, and tick 1000 names the same step on the room and on every client. Tick, command frame
Predicted The client runs a rule ahead of the room, with the room’s own code, and shows the result at once. The room’s result confirms or corrects it. Client-side prediction
Predicted trait State on the player’s own character that the client predicts and the room can correct, such as a dash’s charges. Predicted property, owner-predicted ghost field
Predicted command An action declared with defineCommand and predicted: true: it runs on the client on the tick the player sent it and on the room on that tick, or on the room’s next tick where it arrives up to its lateTicks late, and the room’s result confirms or corrects it. Any action a player takes can be one: a dash, a reload, a cast. Input event, predicted RPC, ability activation
Predicted system A system that steps a player’s character. The room and the client both run it, and the client re-runs it during a correction. Predicted simulation, FixedUpdateNetwork
Correction The room’s result for a past tick differed from the client’s. The client takes the room’s values for that tick and re-runs every tick since. Server reconciliation, rollback and resimulation
Lead How many ticks the client runs ahead of the room, so each input arrives before the room needs it. Command lead, input buffer
Authoritative The world that decides outcomes: the room, or the one world of a single-player game. step.authoritative is true there. HasAuthority(), IsServer
  • Controls that answer at once, at any ping. The engine predicts the player’s movement, jump, turn, cooldowns, resources and ability casts. A key press changes the character on the client’s next step, normally within 17 ms, whether the connection is 30 ms or 300 ms.
  • A room that decides every outcome. The room simulates every player’s character from its inputs alone. A modified client cannot run faster, teleport, deal damage or hand itself an item: it can only send inputs, and the room runs them under the game’s rules. The game writes no anti-cheat code for movement, hits or outcomes; its own rules still check what a command asks for, as Send the room a command says. Engines that let each client run its own character and report where it is, as Roblox does by default, leave those checks to each game’s scripts. Fair play, built in lists what the room refuses.
  • One rule, written once. A mechanic is one TypeScript system, and the room and the client run the same function. No client copy of a rule has to be kept equal to a server copy.
  • A choice for each mechanic. A mechanic is networked one of six ways, from decided by the room alone to owned by the client. Each way is a few declarations on a trait, a command or a system, and the engine’s own mechanics use the same declarations a game does.
  • Mistakes named while you build. A development client in a room runs seven checks and two warnings, and names each mistake in the console with its fix. Debug prediction lists them.
  • No server to run. The platform hosts the room. A single-player game needs none, and the same code runs there unchanged.
  • Tested against a real room. The dash, the blink and the strike on Build a predicted mechanic are the engine’s own test mechanics, run against a room on a simulated 150 ms connection with jitter, where none of 744 presses was lost.

Each mechanic is networked one of six ways:

Way What the player feels Who decides Use it for
Room only The result a round trip after the action The room Anything that changes another player, the world or the score
Feedback at once A cosmetic effect at once, the result a round trip later The room A click or key whose result lands on someone else
Predicted The action at once, corrected in the rare case the room differs The room, after the fact What changes the player’s own character alone
The room judges what the player saw A shot hits what the crosshair was on The room, rewound to the shooter’s view Instant-hit shots at moving targets
Client owned The action at once, never corrected The client Games where nobody gains by cheating
No room Everything at once The client Single-player games

To choose, take the first of the following that fits:

  1. The game is single-player. No room.
  2. The mechanic is an instant-hit shot at a moving target. The room judges what the player saw.
  3. The mechanic changes another player, the world, an item, money or the score. Room only, with feedback at once where the action should feel instant.
  4. The mechanic changes the player’s own character alone, and should answer the key at once. Predicted.
  5. Nobody gains by cheating the mechanic, and prediction is more than it needs. Client owned.

The six ways shows each with an example, its code, and its costs.

The engine’s own mechanics follow the same list, and a game gets them with no networking code:

Mechanic Way Why
Movement, jump, turning and the walk to a clicked point Predicted A key must move the character on the next step, and only the player’s own input changes it.
Cooldowns, and mana, stamina and every resource but health Predicted They count on the client between the room’s sends, so the bars move smoothly.
An ability’s cast: its cost, cooldown and cast time Predicted The cast command starts the cast, takes the cost and starts the cooldown at once.
An ability’s effect: damage, its projectile and its impact Room only It changes another player or the world. The client draws a projectile the room created.
Instant-hit shots The room judges what the player saw, feedback at once The shot’s line, flash and hit marker show on the click. The room rewinds the targets and decides.
Damage, health, death and loot Room only They change another player, and two clients must never disagree on a kill.
Monsters, their AI, projectiles and summons Room only, created by the room An entity two worlds could each create would exist twice. The room creates it and streams it.
Item use and equip Room only An item and what it grants are worth something to every player.
Other players The room’s stream, smoothed A client cannot know another player’s input, so it draws other players where the room last put them.
The camera and the HUD Client owned Nobody else sees them, and nothing in the world depends on them.

Fast action games predict the player’s own character and roll back when the server disagrees. Large online games keep spawns and outcomes on the server and cover the wait with cosmetic effects. This engine does both, with no networking code in the game:

Engine The player’s own character A game’s own predicted mechanic
This engine Predicted by the engine, decided by the room A predicted trait, a predicted command and a predicted system, in TypeScript, the same code on both ends
Unreal Predicted by the character movement component, decided by the server Extended movement code in C++, the Gameplay Ability System’s prediction, or the Network Prediction plugin
Unity Netcode for Entities Predicted where the game writes its systems in the prediction group Systems in the predicted simulation group, re-run on rollback
Photon Fusion In its client-server modes, predicted where the game writes it in FixedUpdateNetwork Networked properties and tick input, re-simulated on rollback
Roblox Run by the client that owns it, by default, with the game’s own server checks. Server Authority, which a game opts into, moves it to the server with prediction With Server Authority, code bound with BindToSimulation; without it, the game’s own scripts and checks
Godot and PlayCanvas No prediction built in The game writes its own, or adds a library

Here the room runs every player’s character, so a game writes no server checks for movement, hits or outcomes.

  • The six ways: each way with an example, its code, what the player feels, and when to use it.
  • Build a predicted mechanic: a dash with charges and a cooldown, step by step, then a sprint, a knockback and a blink, and a strike whose damage stays on the room.
  • How prediction works: ticks, the lead, late input, what a correction does, and what other players see when.
  • Debug prediction: what a mechanic that fights the room looks like, and the checks that name the cause.
  • Multiplayer: the room itself: running one while you build, joining, drops, bots and limits.