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

Multiplayer

A multiplayer game runs in a room: one running copy of the game that players join together. The room runs the game’s world on a server the platform hosts, decides every outcome, and streams the world to each player’s client, the game running in that player’s browser. You do not write a separate server application. The engine networks its own movement, weapons and items, and a mechanic of the game’s own picks how it is networked, as Networking shows. A room holds 20 players unless the game sets another number, from 2 to 100. A single-player game is played alone, with no room, and keeps its saves and progress all the same.

A game is played alone or in a room, never both, and its package.json says which: a game that names spawnite.room always plays in a room and passes its room to defineGame({ room }), and a game that names none is played alone. The template you create the game from writes it: spawnite create --room, or the MCP’s new_game with room: true, gives a new game a room, and Templates says which templates offer one.

Give a game a room when people play it together: they share one world, the room decides every outcome, and they talk over voice. Leave it alone when one person plays, against the game or its bots. A game played alone runs in the player’s browser and nowhere else, and costs the platform no machine time. It keeps:

  • the player’s saves, which the platform keeps for every account and guest, as Saves says;
  • worlds of the player’s own where the game declares worlds, the player’s save slots, which no room opens, as Worlds on a page says;
  • the player’s coins, in the wallet, which the player’s save carries;
  • everything the engine runs on a page: the character, physics, bots of the game’s own and the devtools.

It has no voice and no chat, which run in a room.

A room’s cap, which the game sets, is 2 to 100 players, since a game for one player is played alone. A room still runs from its first player. defineRoom({ maxPlayers: 1 }) is a type error, and a game played alone that calls defineRoom is refused by the game’s lint rule room/no-define-room-alone, and by spawnite build and spawnite publish, each naming the fix. So is a game in rooms that gives defineGame no room. The platform checks again on its own: the upload refuses a version that is played alone and names a room’s scene or settings, or that runs a room for one player, and no room ever starts for a game played alone. A version published before the rule that breaks it is withdrawn: it leaves the store, its link loads nothing and says why, and spawnite versions list and the creator site say why and what to change. A new version that passes lists the game again. Nothing is deleted.

To move a game into a room later, add the spawnite.room key that Run a room while you build shows and install @spawnite/room as a dev dependency, at the release of the game’s @spawnite/engine: the room takes the game’s engine as a peer and runs it. A player’s save stays with the game either way, but a room writes a room game’s save, and keeps less than a page does. spawnite build refuses a persisted store and the other parts a room cannot keep, as Saves in a room says, so move that state into a plugin’s save first. To move a room game to played alone, delete the key, the dev dependency and the game’s room.

  • A room that runs the game. The room steps the game’s own scene 30 times a second, or 60 where the game asks, decides every outcome, and sends each player an update each tick, or fewer where the game asks. Choose a tick rate and Choose a send rate give the CPU and the bytes measured.
  • Prediction. Each player’s client runs their own character ahead of the room, so a key moves it at once, and the room corrects it where they differ, as The player’s own character comes first says.
  • Several players in one run, for your agent. spawnite play start --pages 2 opens a second player’s page beside the first, and --bots <n> adds bots. spawnite play join joins several headless players to a room and says what each saw, and spawnite play room plays the room with bots and no browser.

To play with just your friends, publish the game unlisted and share the keyed link. An unlisted game stays off the store, only people with the link can join it, and it runs one room at a time, so everyone with the link plays in that room until it is full. It needs nothing more. A friend who opens the link while the room is full is refused with “The game’s room is full. Try again in a minute.”, and can try again to join once a seat is free.

In a public game, Play seats each player in the game’s fullest open room that still has a seat. Friends who press Play close together usually share a room, but nothing holds a seat for one of them. Browse lists every room and listed world, friends first, and a player picks one there. Join on a friend’s presence seats the player in that friend’s room.

A game whose rooms hold a world gives its players worlds that remember: a world’s room starts for its first player, so friends come back to it alone, and its owner shares a code. defineGame({ worlds: { playerWorlds: "private" } }) lets players make their own, as Worlds says.

The player app draws the worlds screens beside Play, and a game draws its own menu on useWorldDirectory(). It reads the player’s worlds, each with its owner’s name in ownerName, and asks the app for each verb. The app asks the player first where a verb cannot be undone, opens a world to more people, or acts on another person, and each verb answers done, cancelled or refused with a reason. useWorldMembers(worldId) reads a world’s people by their player ids in the game, and useWorldBrowse() reads Browse. Each place Browse lists carries createdAt, when the world was made or the room opened, in epoch milliseconds, so a game can list the newest first.

A listed world whose owners turned on “Ask first” takes a stranger by a request: requestToJoin(worldId) asks, and its owners read the requests with useWorldJoinRequests(worldId) and answer them with acceptJoinRequest or declineJoinRequest. Under spawnite dev, a stand-in answers with one development world, and spawnite play start --worlds seeds a playtest’s worlds, as Worlds in a playtest says. The following menu lists the player’s worlds with Play and Manage, which opens the app’s page of the world, and says why a verb was refused:

packages/engine/test/outside/WorldMenu.tsx
import { Fragment, useState } from "react";
import {
Button,
Panel,
Slot,
Text,
useWorldDirectory,
WorldDirectoryStatus,
} from "@spawnite/engine";
/** The player's own worlds, each with Play and Manage, and New world: the
* game's own menu over the player app's directory. Manage opens the app's
* page of the world, with its codes, members and delete. */
export function WorldMenu() {
const { status, directory, join, manageWorld, create } =
useWorldDirectory();
// Why the last verb was refused, such as the player's world limit.
const [refusal, setRefusal] = useState<string | null>(null);
const show = (result: { message?: string | null }) =>
setRefusal(result.message ?? null);
if (status !== WorldDirectoryStatus.Ready || directory === null)
return null;
return (
<Panel slot={Slot.Left}>
{directory.mine.map((world) => (
<Fragment key={world.id}>
<Text>{world.name}</Text>
<Button
onPress={() =>
void join({ worldId: world.id }).then(show)
}
>
Play
</Button>
<Button onPress={() => void manageWorld(world.id)}>
Manage
</Button>
</Fragment>
))}
{directory.rules.isCreationAllowed ? (
<Button
onPress={() =>
void create({ name: "New world" }).then(show)
}
>
New world
</Button>
) : null}
{refusal ? <Text>{refusal}</Text> : null}
</Panel>
);
}

In a public game, a player opens a private room for the people the player invites, as Roblox’s private servers work. “Play with friends” on the game’s page shows the owner’s room’s link, Copy and the device’s Share, and the owner’s friends, each with Invite. Anyone with the link joins the owner’s room. A friend the owner invites sees the invite on the site, and a friend of the owner sees Join on the owner’s row while the owner plays. Inside the game, the app’s controls over the frame show the same link and invites.

The room starts for whoever joins first through the link, and runs while anyone is in it, one player included. It closes a minute after it empties, as every room does, and the link stays: the next join starts a new room. The owner’s New link stops the old link for anyone not yet in. Private rooms are free. Play and Browse never send anyone into one, and an unlisted game has none, since everyone with its link shares its one room.

A private room is a room of the kind Play opens, so a game needs no code for one. A game whose Play opens a world has none, because its worlds are its private places. defineRoom({ privateRooms: false }) turns them off, for a game whose scores must come from public rooms alone.

The room reads the private room it runs with readPrivateRoom(world), which answers { ownerPlayerId }, the owner’s id in the game as readPlayerId names a player, or null in any other room. Roblox reads PrivateServerOwnerId the same way. Each page reads the same, where usePrivateRoom() is its hook. It holds from before the first player joins to the room’s end, and a teleport to a fresh room carries it along. A lobby lets the owner alone start the match by checking the start command’s sender against it in the room. A game keeps a private room’s scores off a board by sending none while it reads one.

usePrivateRoomMenu() gives a game’s own menu the app’s verbs on its private room, each answering done, cancelled or refused with a reason, as the directory’s verbs do:

  • inviteFriends(): opens the app’s sheet, with the link, Copy, Share and the player’s friends with Invite.
  • ban(playerId): bans the player with that id in the game, which only the owner may ask, and the app confirms with the owner first.

The owner also bans from the sheet, which lists the room’s players with Ban and the banned with Lift ban. A player the owner blocked stays in the room until banned, so the sheet lists that player first and says so. A banned player leaves the room at once and joins it no more, by any link, a friend’s Join or an invite, until the owner lifts the ban.

directory.friendsOnline lists the player’s friends who play the game now, by name, as Roblox’s Player:GetFriendsOnline() does. Each holds the friend’s playerId, name and the world the friend plays in. The world is null where the friend’s room holds none, or where the player may not follow the friend in, such as a private world the friend only visits. join({ friend: playerId }) takes the player there behind the friend.

A world a player makes lets a friend follow its owner or a member in, as a visitor, until its owner turns that off with setOpenToFriends(worldId, false). A visitor there cannot bring a friend of their own.

Each verb of useWorldDirectory() answers done, cancelled or refused with a reason. Those marked “asks the player” wait for the player’s confirm in the app’s sheet:

  • create(options): makes a world, asks the player for a listed one.
  • join({ worldId } | { code } | { friend }, { hint }): plays a world, by its id or a code, or behind a friend who plays the game now, with an optional join hint.
  • shareWorld(worldId, { hint, codeKind }): makes the world’s link and shows it in the app’s share sheet, as Codes and links says.
  • inviteFriends(worldId): opens the app’s world page, where the owner invites friends by name, which makes each a member.
  • manageWorld(worldId): opens the app’s world page, with its codes, members and settings.
  • newCode(worldId, kind): issues a new invite or visit code, asks the owner, and stops the old one.
  • rename, setSettings, setRegion, setFavorite: change the world’s name, settings, region or the player’s favorite.
  • setListed, setOpenToFriends, setApprovalRequired: list it in Browse, let friends follow its owners and members in, on for a world a player makes, or make strangers ask first, each asks the owner when it opens the world to more people.
  • requestToJoin, cancelJoinRequest, acceptJoinRequest, declineJoinRequest: a request to join a world that asks first, and its owners’ answer, each asks the acting player but a withdrawal.
  • removeMember, ban, unban, addCoOwner, removeCoOwner, transferOwnership: act on a person by the target’s player id, each asks the acting player.
  • deleteWorld, undeleteWorld, leave: delete a world or leave one shared with the player, each asks the acting player, or bring a deleted one back.
  • reportWorld(worldId) and browseWorlds(): open the app’s world page, where the player reports it, or its Browse.

The room reads each player’s standing in its world with readWorldStanding(player): owner for the owner and the owner’s co-owners, member for a member, and visitor for anyone else. A visitor came by Play, Browse, a visit code, a share link by the world’s id or a friend’s presence. WorldStandingChangedEvent says when a standing changes while the player plays. A standing is not a right to build: what a visitor may do is the game’s own rule, so decide it for every world game.

A friends’ building game lets owners and members build, and lets a visitor look and talk. In a world Play filled, which the creator owns, it lets visitors build too, so a new player who lands there by Play can join in. The room checks the rule in each command that changes the world, with readWorldStanding(player) and readHeldWorld(world)?.isCreatorOwned, and declines the rest, as Commands shows.

A world has two codes, each its owners issue again with newCode. An invite code makes the player who opens it a member, who comes back through “Shared with you” with no code. A visit code seats the player for the session as a visitor. The app’s world page shows both codes and “Copy invite link” to its owners.

shareWorld(worldId, options) makes a link from inside the game and shows it in the app’s share sheet, with Copy and the device’s own share. With no codeKind, the link names the world by its id and admits whoever the world admits. With codeKind: "invite" or "visit", it carries that code, its owners alone may ask, and the code stays as it is.

A link can carry a join hint: the name of a place in the world, and an optional id, such as Ada’s house. The game lists the names in its room, defineRoom({ joinHints: ["gate", "house"] }), and registers the room, so every hint is typed by the list:

  • shareWorld(worldId, { hint: { name: "house", id: adaId } }) and join({ worldId }, { hint }) carry one, and teleportPlayers takes one in its options.
  • The room reads it with readJoinHint(player), which answers { name, id }, or null for a join with none. Place the player’s character from onPlayerReady, which runs once the player’s save restored, so a saved position does not move the character back. A page back within the player’s hold, a link opened in the tab the player plays in among them, takes the held player back with no new hint.
  • A link is outside input. A deployed room seats a player whose hint names no listed name with no hint, and logs it, and a development room throws. Check the id names a place the player may reach before placing the player’s character there.

useHeldWorld() reads the world the page’s room holds, as readHeldWorld reads it in the room: its id, name, owner, region, settings and listing, or null in a room that holds none. ownerName is the owner’s display name whether or not the owner is in the room, or null for a world the platform owns; it is text to show, and ownerPlayerId says who the owner is. In a game played alone it reads the player’s page world, as Worlds on a page says. Everyone in the room reads the same, settings included, so a secret belongs in the world save.

A world board’s handle takes its id, so the board of the world the room holds reads as follows:

packages/engine/test/outside/WorldBoard.tsx
import {
Text,
useLeaderboard,
useHeldWorld,
type LeaderboardHandle,
} from "@spawnite/engine";
/** A board declared with `parent: "world"`, such as
* `leaderboards.harvest`: its handle takes the world's id. */
interface WorldBoardProps {
board: { for(worldId: string): LeaderboardHandle };
}
/** The board of the world the player's room holds, or nothing in a room
* that holds none. */
export function WorldBoard({ board }: WorldBoardProps) {
const world = useHeldWorld();
if (world === null) return null;
return <BoardRows board={board.for(world.id)} />;
}
/** One board's rows, top first. */
function BoardRows({ board }: { board: LeaderboardHandle }) {
const read = useLeaderboard(board);
return (
<Text as="ol">
{read.rows.map((row) => (
<Text as="li" key={row.subject.id}>
{`${row.rank}. ${row.name} ${row.score[0]}`}
</Text>
))}
</Text>
);
}

The following panel names the world the room holds and sends a friend to its gate, with the hint the room reads as the friend joins:

packages/engine/test/outside/WorldShare.tsx
import { useState } from "react";
import {
Button,
Panel,
Slot,
Text,
useHeldWorld,
useWorldDirectory,
} from "@spawnite/engine";
/** The world the player's room holds, by name, with a button that sends a
* friend to its gate: the app's share sheet shows the link, and the
* room reads the hint as the friend joins. */
export function WorldShare() {
const held = useHeldWorld();
const { shareWorld } = useWorldDirectory();
// Why the app made no link, such as a world the
// player cannot share.
const [refusal, setRefusal] = useState<string | null>(null);
if (held === null) return null;
return (
<Panel slot={Slot.Left}>
<Text>{held.name}</Text>
<Button
onPress={() =>
void shareWorld(held.id, { hint: { name: "gate" } }).then(
(result) => setRefusal(result.message),
)
}
>
Send a friend to the gate
</Button>
{refusal ? <Text>{refusal}</Text> : null}
</Panel>
);
}

The room loads its scene’s file and nothing else of the game, so that file exports, or re-exports, each declaration the room reads. spawnite build fails where the scene’s file exports a game other than the one src/game.ts exports, and the room refuses a scene’s file that exports room: the room reads it off the game.

Export What it is Declared in
game The game, defineGame: its room, its worlds, its plugins, its physics and every record it keeps src/game.ts
leaderboards The game’s boards, defineLeaderboards src/leaderboards.ts
products What the game sells, defineProducts src/products.ts
textChat The game’s text chat, defineTextChat src/game.ts
timeline What a run records the scene’s file
bot What a bot does the scene’s file

A keyed save needs no export: a room opens a key by its declaration, which the scene’s own imports bring in. The room refuses a scene’s file that exports movement or systems, and names where each is set now.

The room runs the same simulation as the client: the scene’s own file, headless, stepped at the game’s tick rate, 30 times a second unless the game asks for 60. Each step is a tick, and the room and every client number the ticks alike. It sends the world to every client at the game’s send rate, once a tick unless the game asks for fewer: a snapshot when a player joins, and after that an update with what changed.

A player’s client does three things:

  • It sends the player’s input: the input of each tick, where the player clicked to walk, each shot, and the game’s own commands. It never sends where the player’s character is.
  • It runs the player’s own character ahead of the room, so a key press moves the character at once, even on a phone far from the room. This is called prediction.
  • The engine draws every streamed entity, the player’s own character among them, and smooths every other one between updates. Game’s replicas lets a game draw the stream itself. A dynamic physics prop draws where the room puts it. The client also simulates its body, which can drift from the room’s, so the room alone decides what the prop stops.

The room runs each input under the game’s rules and decides every entity, the player’s own character included. With each update, it tells the client where the player’s character stands and what its predicted traits hold. Where the client has the character elsewhere, the client takes the room’s values, steps the character again from there, and blends it to the result, as What a correction does explains.

A behaviour declares where it runs, as Entity describes. A client in a room skips each behaviour that runs in the room, such as Pickup, Health and Chase, and draws what the room did instead. Authority lists which end steers each kind of entity.

  • Players. A room holds 20 players unless the game’s maxPlayers sets another number, 100 at most, a dropped player’s kept character among them. A join past it is refused, and told how full the room is.
  • Updates. One a tick: 30 a second by default, and 60, 30 or 20 at 60 ticks, as the game’s sendsPerSecond sets.
  • A dropped player. The character stays 15 seconds after a close frame, as from a reload or a closed tab, and 30 seconds after a broken connection, for the player to come back to, unless the game’s rejoinHoldSeconds sets another hold. A leave frees it at once.
  • Seats across games. An account holds a seat in three games at once, and a guest in two. A seat whose room has not opened is freed three minutes after it was taken.
  • A silent connection. The room drops a connection it has not heard from for 15 seconds, and the player rejoins. The client reconnects once it has heard nothing from the room for 15 seconds.
  • A client that falls behind. Once more than 1 MB of updates has waited for one client for 30 seconds running, the room drops that client’s connection at its next update, and the player rejoins.
  • A socket that never joins. The room ends it after 10 seconds, and holds at most two for each seat.
  • Input. One input for each of the room’s ticks, 1 to 12 ticks in a message, which names its first tick, sent as bytes on the binary wire. A game declares at most 32 held inputs across its plugins. A client may send 120 messages at once, then two for each of the room’s ticks; the room drops the rest and keeps the connection. Where a player’s input for a tick has not come, the room steps the character on the last input for 15 ticks, a quarter of a second, then stands it still, and drops an input that comes after its tick.
  • Walks. Eight walks at once, then five a second.
  • Item verbs. Eight of each verb at once, then four a second.
  • Commands. Each command’s own perSecond past its burst, a predicted command’s included. At most 64 of a player’s commands wait for a result at once; a client past that breaks the protocol, and the room closes its connection.
  • Command size. A command’s payload holds at most 16 KiB, and the value it returns 1 KiB. A world throws as it is made for a command whose fields could pass either, and the room’s socket takes no frame past 32 KiB.

A game with a room names it under spawnite.room in its package.json and gives defineGame its room. You don’t write either by hand in a new game. spawnite create --room, or the MCP’s new_game with room: true, writes the key, pointed at the template’s scene, adds room: defineRoom() to the game, and installs the room. The page joins the room spawnite play start names in its address, as The page’s address says. A template that plays alone refuses --room. For the example template, it writes the following:

{
"spawnite": {
"room": {
"scene": "./src/scenes/Run.tsx"
}
}
}
  • The key itself says the game plays in a room, which is what the tools below start. A template that plays alone unless it is created with --room, such as the example, offers its room under spawnite.template.room, which only the registry reads, and spawnite create --room writes it as the game’s spawnite.room. spawnite list and the MCP’s list_templates say which templates play in a room, which play alone, and which can do either.
  • scene is the scene the room runs. The room loads that file alone, so the file re-exports what the room reads from the game, as What the room’s scene exports lists.
  • env is optional and holds the room’s environment while you build, such as "PORT": "8788". A room keeps the room’s half of a replay while you build, with no setting, which spawnite replay rerun, replay check and replay state read.

A creator uses the following settings of a development room’s environment, each set in env, or for one run with --room-env NAME=VALUE:

  • PORT: the port the room listens on.
  • ROOM_REPLAY=0: keep none of the room’s half of a replay, as a measured run that should not pay for it does.
  • ROOM_EDITS=1: apply the devtools’ edits from a client.
  • ROOM_INVULNERABLE=1: give every player’s character the InvulnerableTrait trait, which Health spares.
  • ROOM_SAVES=1: keep players’ saves in files in a room the CLI starts, rather than in memory for the room’s life, as Saves in a room says.
  • ROOM_HEARTBEAT_SECONDS: the seconds between two heartbeats, which hitches reads.
  • MAX_PLAYERS, TICK_RATE and SENDS_PER_SECOND: the room’s maxPlayers, tickRate and sendsPerSecond, over the game’s, as Set the room’s players and rates says.

The client joins the room through <Game>’s room prop, a RoomOptions from @spawnite/engine with the room’s address as url and the player’s name as playerName. The page’s address goes over the prop, as The page’s address says, so spawnite play start reaches every game. The arena passes the room its own spawnite.room runs, so a page opened with no ?room= joins it:

games/arena/src/app/app.tsx (part)
/** The room every page joins: the port the game's `spawnite.room` gives
* its room, under a name of two random words, so two tabs join as two
* players. `?room=`, `?name=` and `?wire=json` in the address go over it. */
const room: RoomOptions = {
url: "ws://localhost:8787",
playerName: `${pickWord(firstWords)} ${pickWord(secondWords)}`,
};

A room the platform’s backend runs seats a client only with a seat ticket, the pass the backend issues when it gives a player a seat in that room. In the platform’s app, Play takes the seat and hands the client the ticket and the room’s address, and the engine joins that room in place of the one the prop names, under the player’s name in the app. Outside the app, as on a game’s dev server, the client plays the room the prop names. A room with no backend, such as the one a game runs while you build, seats any client without a ticket.

Once created with --room, the example’s room runs its Run scene. Every player in the room plays the room’s one match, which, as every room’s match does, waits for the first player to open its scene, here by pressing Play. The lobby stays each client’s own menu.

spawnite play start starts the game’s room on a free port beside its dev server, and passes the room’s address in the page’s room parameter, so the page it opens plays in a fresh room. It holds the room with its page, so the room’s clock steps only on command, and --bots <n> adds bots that play until the session stops, so an agent pauses a live fight, steps it and shoots it from any camera, as Directing a moment says. spawnite play join joins players’ clients to the game’s room, or to any room by its address, and says what each saw.

The room restarts on its scene when a file the scene loaded changes, and logs a restarted line that names the file. It loads the game’s Vite config with Vite’s runner config loader, which writes no temporary file, so Node’s watch sees no change while the room starts. A config that loads under vite but not under vite --configLoader runner, such as a CommonJS vite.config.cjs, fails the room’s start. spawnite play room runs its room unwatched, so an edit never ends a measured run.

The room gives each player who joins a character at the scene’s spawn. A game that places the character itself, such as at the player’s own plot, lists characters({ autoSpawn: false }) and calls spawnCharacter from the player’s join, as the player page says.

The engine follows one rule for the player’s own character: the client shows at once, at the frame rate, whatever it can know, and the room’s update corrects it afterwards. The client runs the character’s movement, jump, turn, cooldowns and resources ahead of the room, with the same rules the room runs, and the room’s result confirms or corrects them.

The client steps the character at the room’s tick rate, 30 times a second by default, each step on that step’s own input. After each frame’s steps, it sends the room one message that carries the input of each tick the frame stepped: at 60 frames a second and 60 ticks, one tick a message. Each end writes each tick’s input into the character’s InputTrait as it steps that tick. A game system that writes the character’s input therefore sees its own write only until the next tick, in the room and on the client alike.

The client shows the following at once:

  • The character’s turn, while the camera’s lock or first person holds, and the look’s pitch in the character’s spine and arm, every frame.
  • Cooldowns counting down, and mana, stamina and every other resource but health regenerating, between the room’s updates. A cooldown or a cost that only a rule in the room starts, such as an item’s use, reaches the client with the room’s next update, which corrects the client from that tick.
  • Movement, the jump and the walk to a clicked point, stepped at the room’s tick rate. A key press moves the character on the next step, at most a tick after it, 33 ms at 30 ticks a second and 17 ms at 60, and reaches the room with that step’s input as the frame ends.
  • An ability’s cast, on the frame of the press: its cost off the bar, its cast bar, clip and charge, the character’s turn toward its target, its refusal line, and at its release the spent cost and the cooldowns sweeping. Abilities names the casts that wait for the room: one that walks the character into range first, and one of an ability registered predicted: false.
  • A weapon’s shot: its line, muzzle flash, sound and camera kick, held to the weapon’s rate on the client. An instant weapon’s hit marker shows on the click, and the client takes it back if the room refuses the shot.
  • What the character holds, its head turn, its footsteps and the camera.

The room alone decides the following, and the client shows each when the room’s update arrives:

  • Damage, health, being downed, death and respawn.
  • An ability’s effect: its projectile, its impact, its strikes, the damage numbers and the slow it leaves.
  • A projectile weapon’s projectile.
  • The bag, what the character wears and what it equips.
  • The wallet, the score, the timers and the match.

A game’s own mechanic chooses the same way. Networking explains the choices, with examples. It covers the room clock and the lead, which is how many ticks the client runs ahead of the room, predicted traits and predicted commands, corrections, and the checks a development client runs on a predicted mechanic.

The room checks what each player does, and sends each client only what the game lets its player see: a client never receives an entity its visibility keeps from the player, nor a trait outside its reach.

The room runs every player’s character from that player’s input, so a client changed on the player’s own device gets from the room only what the room’s rules allow. In a room the platform hosts, with the engine’s default movement and weapon rules, the room checks the following for every game, with no code of the game’s own. A development room started with ROOM_EDITS=1 also applies the devtools’ edits from any client, to any entity, so it trusts its clients more than a hosted room does.

The checks:

  • Input. The room steps each character once a tick, on the input named for that tick, at the speed the game gives it and into the walls of the room’s own world. A client that has the character somewhere else is corrected.
  • Shots. The room judges each shot itself. It rewinds the targets to where the shooter’s screen showed them, by the shooter’s measured latency, held within 200 ms of it and at most 1 s back. It refuses a shot from a downed or disarmed character, from a weapon the character does not hold, faster than the weapon’s rate allows, from more than 2.5 m from the middle of the character’s body in the room, or from behind cover.
  • Outcomes. Only the room writes the wallet, the bag, the score, the timers and the match. A client reads them, and the room ignores a client’s write to them.
  • Commands. The room refuses a command whose payload does not match its declared shape, that arrives faster than its rate, or that acts through an entity the player does not control, and runs a resent command once.
  • Predicted commands. The room runs each predicted command once, never before the tick it names, and within the command’s rate. It runs on that tick, or on the room’s next tick where the command comes up to its lateSeconds late, 0.28 seconds by default, 17 ticks at 60 ticks a second. It answers a second copy with the first result, refuses one stamped more than a second ahead malformed, and refuses one past its lateSeconds late. A client that holds a command back delays its own action and gains nothing: the wait earns the command no extra rate.

For example, a modified client sends input at twice the rate, to run its character at twice the speed. The room steps the character once a tick on the input named for that tick, so the extra input names ticks the room already holds, or ticks more than a second ahead, and the room drops it. The character runs at the normal speed however fast the client sends. A client that holds its input back gains no time either. The room steps the character anyway, on the last input it has for a quarter of a second and then standing still, and drops the held input when it comes. The modified client, which ran its character elsewhere, takes the room’s position once the room’s update arrives, and its character snaps back to where every other player sees it.

Each check a shot meets is a named rule that a game changes for the whole game or one weapon. The rules a shot meets describes the rules and their costs.

The room judges a shot where the shooter’s screen showed its target. Shots delayed by a network stall of up to 0.65 s still count. A refused shot appears under its rule in the room’s log and heartbeat, and the client removes its hit marker.

judge: ShotJudge.Page lets each client decide its own hits while the room still runs the rules. Pass the setup writer to registerShotSettings(writer, { judge: ShotJudge.Page }) for the whole game. A weapon’s own judge overrides it.

The room does not check everything:

  • A game’s own command is checked only by the game. The system that reads it decides what the player may have, such as whether they can afford an item or stand close enough to open a door, from the room’s own world, as Send the room a command says. A command that carries a price, a score or a position asks the room to take the client’s word for it.
  • Unless the game turns on interest culling, every client receives every entity its visibility lets the player hold, wherever it stands, and every trait within its reach. The room does not work out line of sight, so a modified client can draw a player behind a wall unless the game’s own system hides that player with setVisibility. Keep a secret, such as another player’s hand of cards, in a trait only its owner, its audience or the room receives, as Choose who a trait reaches shows.

defineRoom declares how many players one room holds, how often its world steps and sends them updates, and how long it holds a dropped player. The game takes it as defineGame({ room }), and the room reads it off the game its scene’s file exports:

packages/room/test/outside/room.ts
import { defineGame, defineRoom } from "@spawnite/engine/core";
// A party game of quick reactions played on phones: eight players, the
// world stepped 60 times a second rather than the default 30, and sent
// 30 times, which halves what each phone downloads at 60 ticks. The scene
// re-exports the game from src/game.ts.
export const game = defineGame({
name: "party",
start: "party",
room: defineRoom({ maxPlayers: 8, tickRate: 60, sendsPerSecond: 30 }),
});

The room reads these settings, each optional:

  • maxPlayers: the most players one room holds, a whole number from 2 to 100, and 20 when left out. A game for one player is played alone, with no room. A dropped player’s kept character counts. A game for more players runs several rooms. Holdfast declares 4.
  • tickRate: how often the room’s world steps, 30 or 60 times a second, and 30 when left out, in the room and in a run of the game alone. Every system, the physics and each page’s prediction step once a tick, and a system reads a tick’s length as step.deltaSeconds.
  • sendsPerSecond: the room’s updates a second, a number that divides the tick rate: 30 at 30 ticks, and 60, 30 or 20 at 60 ticks, which a send rate other than 30 names beside it. Left out, the room sends once a tick. Each update carries the world’s changes and each player’s own character as the room has it.
  • rejoinHoldSeconds: how long the room holds a dropped player’s seat and character for them to come back, above 0 and up to 300 seconds. Left out, it is 15 seconds after a closed page and 30 after a broken connection, as When a player drops says.
  • voice: whether players talk, and off when left out. true turns voice on for the game, as Turning voice on and off says.
  • privateRooms: whether a player may open a private room in the game, and on when left out. false takes “Play with friends” off its page.
  • kinds: the kinds of room the game opens, by name, such as { lobby: {}, arena: {} }, each saying whether its rooms hold the game’s worlds and, with its own maxPlayers, how many players they hold. Play opens the first, and a teleport opens any other, as Teleports between rooms says. Left out, the game has one kind.
  • joinHints: the names a link or a teleport may carry for the room to read, as Codes and links says.
  • interest: interest culling, off when left out: each page holds what stands within radius metres of what its player controls and looks through, as Interest culling says. A kind of room may set its own.

The types refuse any other maxPlayers, tickRate or sendsPerSecond in your editor, and a send rate that does not divide the tick rate, such as { tickRate: 30, sendsPerSecond: 60 }. spawnite build writes them, voice off and private rooms off into the bundle’s manifest, and fails where a game in rooms gives defineGame no room, and where a game played alone gives one. spawnite build and the room as it starts check all three settings against the same rules, and a room with settings it cannot read does not start and says why. The platform checks maxPlayers and the two rates again at publish and each time it starts a room, so a room never runs on a value outside the range. While you build, --room-env MAX_PLAYERS=2, --room-env TICK_RATE=30 or --room-env SENDS_PER_SECOND=30 runs the game’s room on another value with no edit; a page takes the room’s rates from its welcome.

30 is the default for a game with rooms: the room steps half as many ticks a second as at 60, so it holds more players on its core, and remote smoothing keeps other players gliding. A run of the game alone, with no room, steps at the same rate, so what you feel alone is what ships. A game played alone steps at 60, since it runs only on the player’s page, and takes defineGame({ tickRate: 30 }) for the other.

Consider 60 for a game whose players aim, dodge or race, where timing is the game. At 60, an input lands on a 17 ms boundary instead of 33, another player is drawn a tick fresher, and a fast body moves half as far each tick, so a thin wall stops a fast projectile more surely. The room’s work grows by less than double: on a desktop core, 100 bots with culling off took 61% of the core at 30 ticks and 90% at 60, measured on 2026-10-11. A room’s heartbeat names its tick rate and each tick’s share of its budget, which spawnite play room reports.

A room sends once a tick by default, 30 times a second at the default 30 ticks. At 60 ticks it sends 60, 30 or 20 times, and a room may send 60 at any size. At 60, each player sees the others sooner. The room’s next update leaves at most one tick after it steps, and the client draws the other players one update interval behind the last update: 17 ms at 60, and 33 ms at 30, the slower rate. A fast shooter or a fighting game, where a hit lands on what a player saw a few milliseconds ago, gains the most from 60 ticks and 60 sends.

Consider 30 sends at 60 ticks for a very large room, which runs lighter at 30, or for a game people play on mobile data, where each player downloads about half as much.

The cost of 60 is bandwidth. Each update carries what changed, and in a game where everyone moves, everyone’s position changes at every update. So each client receives about twice the bytes at 60 as at 30. A client receives every other player’s changes, so its bytes also grow with the room’s size. The following table shows the bytes a second the room sent each client in a light game, the Arena with every bot moving and firing, measured on the platform’s room machine on 2026-10-03, before TCP and WebSocket overhead:

Players in the room 30 updates a second 60 updates a second
12 11.5 kB/s 20.6 kB/s
36 31.7 kB/s 56.4 kB/s
50, estimated about 44 kB/s about 77 kB/s
Each player added, at 12 to 36 0.84 kB/s 1.49 kB/s

A client’s own reading agrees. In a 9-player Arena room played through spawnite play on a development machine on 2026-10-03, over a 30 ms link, the client received about 15 kB/s at 30 updates a second and 30 kB/s at 60 updates a second. It drew the other players about 58 ms behind the room’s last update at 30, and 43 ms behind it at 60, the faster rate. Its lead on the room was the same at either rate, about 6 ticks over a 30 ms link and 12 over a 150 ms one. The room corrected the player’s character a handful of times a minute at most at either rate. spawnite play state names the room’s send rate and that draw delay on its Room: line.

The 50-player row adds 14 players’ worth to the 36-player row. At 60 in a 50-player room, each player downloads about 77 kB/s, about 280 MB in an hour of play, against about 44 kB/s and 160 MB an hour at 30 (estimates). That is little on a home connection, and a large share of a phone’s data plan. A game with more on screen, such as Holdfast’s dozens of monsters, sends more. A room at 60 used 41% of its one core at 36 players, against 34% at 30, about a fifth more. Hosting is free, so the room’s traffic costs a game nothing at either rate.

Each room runs in a container of its own, with one CPU core and 512 MB of memory, and how many players it holds depends on how much the game does each step. The light Arena used 41% of its core at 36 players and 60 updates a second. 50 players at 60 updates fits that core for a game as light as the Arena (an estimate from the 36-player run). 100 players need a game lighter than that: the platform’s own capacity bench at 100 players, with every player firing, needs more than the one core. Room capacity says how to measure your own game before you set maxPlayers that high.

A heavier game holds fewer. Holdfast’s room, with dozens of monsters, held 24 players at 60 steps a second, but its late fights used 79 to 87% of the core, past the 70% at which players’ inputs began to arrive late. That was measured on the platform’s room machine on 2026-10-03, while the room sent 20 updates a second. A game now sends 20, 30 or 60 updates a second, and the Arena’s run above shows the core’s share growing with the rate, so a game as heavy as Holdfast likely holds fewer than 24 at either (an estimate). spawnite play room plays your own game’s room with up to 12 bots and reports its step time, memory and bytes for each wave, so you can measure your game before you set maxPlayers.

A horde, a crowd or a field of crates does not need the room’s full rate for every member. A prefab, a spawn or an <Entity> takes sendsPerSecond, and the room then sends that entity’s changes only that often. With farSendsPerSecond and farDistance, a page far from the entity receives its place less often still. A trait takes precision, and a prefab takes positionPrecision, which set how finely a value travels.

The engine’s tests run the following horde in a real room at 60 sends a second that culls by interest:

packages/room/test/outside/horde.ts
import {
createQuery,
definePlugin,
definePrefab,
defineSystem,
defineTrait,
Phase,
TransformTrait,
updateEach,
type AuthoritativeStep,
} from "@spawnite/engine/core";
/** A zombie's walk: metres a second along x. */
export const ShambleTrait = defineTrait("shamble", { speed: 1.2 });
/** A dial on its back that turns a little every step. Its angle travels
* as the nearest hundredth, so most steps send nothing of it. */
export const DialTrait = defineTrait(
"dial",
{ angle: 0 },
{ precision: { angle: 0.01 } },
);
/** One of a horde: it asks for 20 sends a second, every third send of
* a room at 60, and its position travels as the nearest 5 cm. A page
* more than 30 m from it receives its place 5 times a second, in a room
* that culls by interest. */
export const zombie = definePrefab("zombie", {
traits: [ShambleTrait, DialTrait],
sendsPerSecond: 20,
positionPrecision: 0.05,
farSendsPerSecond: 5,
farDistance: 30,
});
const shamblers = createQuery(TransformTrait, ShambleTrait, DialTrait);
function shamble(step: AuthoritativeStep) {
updateEach(step, shamblers, ([transform, walk, dial]) => {
transform.position.x += walk.speed * step.deltaSeconds;
dial.angle += 0.001;
});
}
/** The horde: listed in the game's plugins, in src/game.ts. */
export const horde = definePlugin(() => ({
name: "horde",
systems: [
defineSystem({ name: "shamble", phase: Phase.Rules, run: shamble }),
],
}));

This room sends each zombie on every third send. The following rules hold for a slower entity:

  • Each page draws it smoothly, one interval late. The page draws each move over the entity’s own interval, so a zombie at 20 sends a second is drawn 33 ms later than one at the room’s rate.
  • A horde spreads over the sends. Each entity’s turn comes from its key, so the members do not all go at one send, and every page receives a given entity on the same sends.
  • Some changes go at once. Its spawn and its removal go at the next send. A teleport and an event emitted on it go at the next send too, with every change it held back. A change of who sees what, such as setVisibility or a new member of an audience, sends every slower entity what it held back.
  • A trait only its owner receives keeps the room’s rate. A Reach.Owner trait travels in that player’s own acknowledgement, which the room sends at its own rate.
  • The room rounds the rate. A rate is a whole number of the room’s sends: 25 in a room at 60 becomes 30. In development, the room says which rate it used. The lowest rate is 4.
  • A shot is judged where the shooter saw it. A rewound read, such as readViewPosition, reads a slower target where the shooter’s page drew it.

Keep an entity a player controls at the room’s rate, or that player’s input shows late. Under interest culling, the room places an entity by the position it last sent, so a slower entity enters a view up to one of its intervals late.

farSendsPerSecond and farDistance take effect in a room that culls by interest. The room in the sample sends a zombie’s place to a page more than 30 m away on every twelfth send. The following rules hold for the far rate:

  • The far rate paces the place alone. A far page receives the entity’s position, rotation, scale and velocity at the far rate. Every other trait reaches the page at the entity’s own rate, so its health or its state is never later than for a near page.
  • The distance is measured as interest measures it: from the nearest entity the page’s player controls or views to the entity’s bounds.
  • A page changes rate at the entity’s next far send. The page takes the far rate a fifth past farDistance, 36 m in the sample, and the near rate again within farDistance, so a player who paces the line does not flip.
  • A far page draws each move over the far interval. At 5 sends a second in a room at 60, the page draws the entity 183 ms later than one at the room’s rate.
  • The room rounds the far rate to a whole number of the entity’s own sends, so every far send is one of its sends. The lowest far rate is 4, and the highest is sendsPerSecond.
  • Some changes reach a far page at once, with the place the room held back: a teleport, an event emitted on the entity, and a change of who sees it.
  • A shot is judged where the shooter saw it, at the rate the shooter’s page held the target at.
  • A room that does not cull ignores the far rate, and says so in development.

A precision is the step a value is rounded to before the room compares it with what it last sent. A value travels as the nearest multiple of the step, so a change that stays within one step sends nothing. The following rules hold for a precision:

  • A precision is a multiple of 0.0001, the finest the stream carries.
  • precision names each field of a trait that every page receives. A trait whose whole value is a number or a vector takes one number.
  • A quaternion is rounded component by component: 0.001 is about a tenth of a degree.
  • positionPrecision is 0.01 m when left out. Keep it below the distance the entity moves between two of its sends, or the entity is drawn stopping and starting.
  • A value that rests on the boundary between two steps still sends each time it crosses.

A mechanic that feels right on your machine can break for a player: your room answers in a millisecond, and theirs in 150. In development, the page plays its room over a slow link you choose, so you see what the player sees before they do:

Terminal window
spawnite play start --latency 150 --jitter 20 --stall 500/10

The link takes the following settings:

  • --latency is the round trip in milliseconds, up to 10,000. Each message to the room, and each message back, waits half of it.
  • --jitter is how much each message’s trip varies, in milliseconds, up to 10,000. Most trips land within it of half the round trip, and now and then one runs two or three times it.
  • --stall <milliseconds>/<every seconds> freezes the link now and then, as a phone’s handover or a busy Wi-Fi does. With 500/10, nothing gets through either way for half a second every ten seconds, then everything held arrives at once. A stall must be shorter than the time between two stalls.

Messages keep their order and none is lost, because the room’s link is a WebSocket, which delivers every message in order. A lost packet reaches the game as a late message, which the jitter and the stall cover, so the link drops nothing. The engine’s room connection holds the messages itself, so the round trip the client measures, the clock it keeps with the room and every correction run on the slow link. A browser’s own network throttling does not reach a WebSocket’s messages. Voice travels on a connection of its own, which the link does not slow.

The same settings work from every tool:

  • A dev page reads ?latency=150&jitter=20&stall=500/10, which play start writes for you.
  • In the devtools, the Performance panel shows the room’s round trip. Beside it, a row of connections sets the link while you play: Direct, Good Wi-Fi (40 ms, jitter 5 ms), Phone, 4G (120 ms, jitter 25 ms, a 400 ms stall every 30 s) and Bad hotel (250 ms, jitter 60 ms, a 1 s stall every 15 s). Custom shows three boxes, the round trip, the jitter and the stall, for any link you type, and holds a link the address set. The choice lasts until the page reloads.
  • The MCP’s start_playtest takes latency, jitter and stall, and starts a headless page on them. A playtest on the creator’s own browser tab plays over the link the creator set in that tab’s devtools.
  • spawnite play profile --dev takes the flags for its page, and spawnite play room for each bot. On play room the times are the game’s, so a run at --speed 4 holds each message a quarter as long on the wall clock. The bots that play start --bots and play profile --bots add play directly.

spawnite play state names the client’s lead on its Room: line: the ticks its clock runs ahead of the room’s, as the room’s answers estimate it, after the round trip. The same line names the bytes a second the client sent the room beside those it received, and the link, such as on a slow link of 150 ms, jitter 20 ms, stall 500 ms every 10 s, and a --until condition reads the link as room.link. The round trip reads at or above the latency: a message waits behind the one before it, and a stall holds the pings too.

A built game carries none of it. The link’s code compiles out of a production build, and a published page ignores the address’s settings, so play profile needs --dev beside the flags.