Scenes
Loading a scene
layers.load(ref, opts?) loads a scene; ref is a scene AssetRef or its identity string:
layers.load("@builtin::scenes.starter_menu") -- by identity
layers.load(asset.ref("@builtin::scenes.test_arena")) -- by ref
Loading a scene as the root replaces the current root (despawning its non-persistent entities), instantiates the scene's entities, applies its lighting / camera / player setup, and runs its entrypoint.luau once. The current root is layers.active.
A load builds each entity from its record in the scene: its id, name, transform, and the components added to it with component.add (@builtin::components.Model, @builtin::components.Light, your own), each with the field values the record holds. Those components then rebuild the engine state they drive, so a Model record brings its mesh and material back. A component written straight into the ECS with ecs.insert / ecs.insertSync (ecs.Mesh, ecs.Material, ecs.Light) lives on the live entity alone: reloading the scene with layers.reload(), or loading another scene and then this one again, brings the entity back with its id and its component records, without that ECS component. (A layers.load of the scene that is already the root leaves the live entities as they are; layers.reload() is the call that builds them again.) Dress an entity that has to come back the same way through a component (entity.component.add("@builtin::components.Light", { kind = "point" }) in place of ecs.insert(id, ecs.Light { ... })), or insert the ECS state again from code that runs on every load: the scene's entrypoint or a component's awake.
local lamp = entity.spawn("lamp")
lamp.component.add("@builtin::components.Light", { kind = "point", intensity = 3 }) -- comes back with the scene
local bulb = entity.spawn("bulb")
ecs.insertSync(bulb.id, ecs.Light { lightType = "Point", intensity = 3 }) -- stays with this load
Root + additive layers
A scene loads either as the root (the main scene) or as an additive overlay on top of it:
layers.load(asset.ref("@builtin::scenes.starter_menu"), { additive = true }) -- overlay, rides on the root
There is exactly one root at a time, plus any number of additive overlays (a HUD, a pause menu). Additives ride on the root and unload with it. layers.list() enumerates what's loaded; layers.onLoad(cb) reacts to loads. Each layer names the scene asset it was loaded from: layer.sceneIdentity (e.g. @builtin::scenes.test_arena) and the asset's layer.guid — so layers.active.sceneIdentity answers which scene is open.
The root is special: it owns the live players registry and the play-mode camera below. Additive overlays don't.
The player intent — how a scene handles players
A scene declares who plays it with a single string player intent in its scene.json:
"spawns"— the scene spawns a player for each joining user from the PlayerSpawns you author into it. The canonical player scene."none"— the scene has no player. Author a Camera entity for its play-mode view. Use this for UI-only screens, menus, cutscenes, and dashboards.
Everything about players and cameras lives as authored entities in the scene's scenegraph. A scene that wants a player says so with "spawns" and carries the PlayerPrototype + PlayerSpawn structure below; a scene that doesn't says "none" and authors whatever Camera it needs.
Authoring a player: PlayerPrototype + PlayerSpawn
A "spawns" scene is built from three authored pieces:
- A PlayerPrototype — an entity (with the
PlayerPrototypecomponent) that roots a player-setup subtree. It's a template, not a live player: in edit mode it's the live authored original; in play mode the engine clones it for each joining user. - A body — the entity named by the prototype's
PlayerPrototype.bodyref (a child of the prototype). It's whatever the author placed there. On spawn the clone's body is adopted as the joining user's avatar. - A CameraRig — a
Camera-component entity under the prototype, scoped OwnerOnly so each user gets their own view. On spawn it follows the user's bound avatar.
A PlayerSpawn — an entity with the PlayerSpawn component — defines where players spawn and which prototype to clone. Its fields:
prototype -- an entityRef to the PlayerPrototype entity to clone
team / role -- optional labels for the spawned player
maxPlayers -- cap on players from this spawn
spawnPolicy -- how repeat spawns are handled
placement -- "at_spawn_transform" places the clone at the PlayerSpawn's transform
On join, the PlayerSpawn clones its prototype; the clone root becomes the joining user's internal identity (it folds into the players registry below), the clone's body (named by PlayerPrototype.body) is adopted as the user's avatar, and the prototype's CameraRig follows that avatar. The engine wires this to the connected-user join event automatically for any "spawns" root scene — you author the structure, the join flow runs itself.
Is the world ready to play yet?
The playable global answers whether the world is ready to play right now (could someone jump in and play it), what is still missing when it is not, and when it first became ready. It reads in edit mode, without entering play: the scene's play entry would spawn a player the person controls. That is a "spawns" scene whose PlayerSpawn names a well-formed PlayerPrototype, whose body carries controls (a component holding an inputMap, such as CharacterController or VehicleController) and whose camera rig holds the player's Camera, with touch controls when the person is on a touch device. In play it reads the player play spawned. The agent building a world states it too (playable.declare({ by, note })) once the game the person asked for can be played, including a game the rule cannot see, and source says which of the two set it. DotBot's build card offers Play from the agent's statement, since the template a world starts from reads playable from its scene before anything was built.
local s = playable.state() -- { playable, source, missing, player, first, ... }
for _, m in ipairs(s.missing) do print(m.code, m.message) end
local ok = playable.wait({ timeout = 60 }) -- hold until it is playable
playable.onChange(function(now) print("playable:", now.playable) end)
The engine judges it on every frame it runs, so a screen offering Play is told by the next frame, and first keeps the moment the world first reached it since it was opened (Unix seconds, engine time and frame) for measuring time to first playable. tools.use("scene", "playable") reads, waits on and states the same milestone from a tool.
The players registry
Reach the live players through the root scene's registry:
local me = layers.active.players.localPlayer -- the player THIS client controls
layers.active.players:count() / :list() -- how many / all of them
layers.active.players:onLocalReady(function(p) end) -- fires once the local player is ready
layers.active.players:onJoin(function(p) end) -- :onLeave too
localPlayer is the multiplayer-safe way to get "this client's player"; the rest are remote. The registry lives on the root (layers.active.players) — additive overlays don't have one.
A player's body — both how it looks and how it moves — is its avatar: a live world entity carrying a visual mesh together with a movement controller. It comes from the scene's PlayerPrototype.body — every connecting player gets a clone of that authored body (see man scene).
localPlayer.avatar is this client's live body entity (a ref). To swap it at runtime, spawn a body and bind the entity — an asset is not a world entity, so compose it onto an entity first:
local body = entity.spawn("hero")
body.component.add("Asset", { source = asset.ref("my_hero") }) -- my_hero: any avatar
localPlayer.avatar = body -- bind the live entity (assign nil to clear)
To make your own avatar the body every player spawns with, point the scene's
PlayerPrototype.body at a body entity whose Asset source is that avatar.
A humanoid body automatically gets the shared retargeting locomotion (any
humanoid clip set plays on it, retargeted onto its rig) where the world holds
the Controllers library, whose characterController package carries
Locomotion; a world without it shows the body in its rest pose. What walks it
is its mover: a component on the body whose .metadata carries the
bodyMover tag. The player body of a clearing or player start carries the
Controllers library's CharacterController (install it in any world: ZeroMind
search Controllers); an avatar names its mover in its controller field and
carries none when it names none. A non-humanoid body (a vehicle, a hovercraft, a custom shape)
is just as valid: it takes the mover and animation you supply. A movement
component of your own replaces the walking by carrying the bodyMover tag,
and the velocity verbs, speed changes, the avatar's animator and a headset
then reach it as they reach CharacterController (the physics guide's
"Movers" section, man topics/physics); scene.player with
roles.controller makes it the mover every player's body moves with. The
avatar asset is the adapt-the-base-character primitive (man avatar).
Only the body bound to the local player answers that player's controls. Every
other avatar you instantiate (an NPC, a mannequin, a preview, another player's
body) stands where it is until something drives it: with CharacterController
as its mover, a component of your own writes its input bus
(inputX / inputZ / inputJump) each frame, the way an AI brain does
(the Controllers library's CharacterController README).
The camera & its controller
The play-mode camera is the prototype's CameraRig — a Camera-component entity scoped OwnerOnly, so each peer owns its own (a camera is never synced). It's authored into the PlayerPrototype and follows the user's avatar on spawn. A "none" scene has no player, so it carries a Camera entity of its own for its play-mode view.
Reach the active play-mode camera as layers.active.camera. It is a handle on
the camera's settings, and cam.entity is the entity ref for the camera itself
— the same shape layers.active.players.localPlayer.avatar hands back for the
player's body:
local cam = layers.active.camera
cam.fov = 70
cam.behavior = cam.behaviors.orbitalFollow -- how the camera moves (an installed behavior)
cam.ready -- is a camera loaded yet
cam.entity -- the camera's entity ref
cam.entity.position -- where it is
cam.entityId -- that entity's id string
How the camera moves is its controller. Two ways to choose one:
- Quick:
cam.behavior = cam.behaviors.X, wherelayers.active.camera.behaviorslists the available controllers by name (every component taggedcameraBehaviorin its.metadata). - Any controller component:
behaviortakes any.component/asset. The Controllers library publishes ready controllers as itscameraRigspackage (orbit and over-the-shoulder follow, first person, chase, a seat camera, strategy, isometric, overhead, side-scrolling and cutscene cameras): a world from theclearingorplayerstart holds it, and any other world installs it withworld.installLibrary({ world = "034d26cf-dc3d-4123-abad-3944f97c6a60", as = "controllers" }); each is@controllers::cameraRigs.<name>, and itschoosing-a-cameraguide says which fits which game.
Setting behavior attaches the controller's component to the camera's entity (and detaches the one it replaces), so the controller is tuned on that component. A component.add of the controller's type configures the instance behavior attached rather than adding a second one, and it is the form a build.luau tunes the controller with: the values it passes are saved with the scene and come back when the scene loads. cam.entity.component.get("third_person_follow").cameraDistance = 6 reaches the same instance for a live change.
cam.behavior = cam.behaviors.thirdPersonFollow
cam.entity.component.add("third_person_follow", { cameraDistance = 6 }) -- tunes the attached one
A follow-style controller tracks the local player's avatar by default; cam.follow makes it follow a specific entity.
Entity lifecycle & replication properties
Two persisted entity-proxy properties control how a player-setup subtree behaves across modes and across peers. They sit alongside temporary / internal as entity-level properties — they are entity modes, not components:
entity(id).participation -- "WorldEntity" (default) | "PrototypeOnly" | "EditorOnly" | "RuntimeOnly"
entity(id):setParticipation("PrototypeOnly") -- a template: live in edit, cloned (not live) in play
entity(id).networkScope -- "Replicated" (default) | "OwnerOnly" | "AuthorityOnly"
entity(id):setNetworkScope("OwnerOnly") -- clone reaches only the owning peer
participationis the lifecycle axis. A PrototypeOnly entity is a template — live while you author in edit, deactivated in play (the engine clones it per joining user instead of running the original). EditorOnly entities exist only in edit; RuntimeOnly entities exist only at runtime and are never saved. A PlayerPrototype root is authored asPrototypeOnly.networkScopedecides what replicates when a prototype is cloned on join: OwnerOnly nodes (like the CameraRig) reach only the peer that owns that player; AuthorityOnly reach only the simulation authority; Replicated (the default) reach everyone. The clone is pruned by each node's scope against the joining user's role.
The entrypoint
Each scene has an entrypoint.luau that runs when the scene loads. It's where per-scene wiring lives: dynamic spawns, event listeners, hooking up the local player. Top-level functions in it are picked up as scene hooks, several of them mode-specific:
onLoad()— fires on load in play mode (gameplay start).onEditLoad()— fires on load in edit mode (authoring / editor setup).onUnload()— fires on unload, always.update(dt)— per frame in play mode, while the gameplay clock runs;editorUpdate(dt)— per frame in edit mode, running or paused. Play-paused ticks neither. This is the scene loader's own dispatch and it partitions strictly on mode; a component'supdatereads the clock rather than the mode, so the two rules differ in edit-running and in play-paused (core/componentshas that table). A tick with nothing to do until something moves ends withlayers.sleepUntil({ changes = { "input", "entities" } }): the scene's next tick runs on the first frame one of the named change clocks moves (or the mode, the pause or the time scale changes), so a still frame runs none of it.localPlayerReady(player)— once this scene's local player is ready (the place to position it or set its avatar);playerJoined(player)/playerLeft(id)cover remote players. (Root scenes only.)
Writing the entrypoint of a loaded scene in edit mode reloads that scene's layer, the way writing its build.luau rebuilds it: the previous load's onUnload runs, the entities, tasks and callbacks that load started end, and the new code runs with its onEditLoad. The reload leaves build.luau answered from the saved scene, keeps your unsaved edits, and posts a notice saying whether the layer came back whole. A write whose code is the code already running (only comments count as none) reloads nothing. In play, a write runs at the scene's next load.
Entities the entrypoint spawns are automatically marked temporary, so they're never written into the scene — the entrypoint recreates them on every load, and baking them in too would double them up. This holds however you spawn them — directly via entity.spawn, indirectly through a module helper the entrypoint calls, or from a deferred task.spawn the entrypoint starts: the marker is inherited from the entrypoint down the call stack at spawn time, not snapshotted in a window. So an entrypoint is the right home for spawned-on-load content: it stays out of scene.json for free. Pass entity.spawn(name, { temporary = false }) to opt one entity out of that default.
An entrypoint that raises is a build that failed part way. The loader runs its body in a pcall, logs the error and settles the layer partial: the entities the scene's records hold stand, and the entities the body spawned and held only in its own locals are despawned, the way any protected call that raises takes back what it spawned (core/scripting-and-tasks). Fix the error and the next load builds them again.
Saving and editing
A scene is content you edit live: load it, arrange entities, then layers.active:save() writes the current scenegraph back into the scene's scene.json. While you edit, the entities you spawn and move are part of the scene — they're tracked live and synced to everyone — and :save() is what consolidates that live scenegraph into the scene file so it loads back the same way. Saving captures entity data, not your entrypoint.luau (that's preserved).
Mark an entity temporary to keep it out of the saved scene:
entity(id).setTemporary(true) -- this entity (and its subtree) is excluded from :save()
Use it for runtime helpers you don't want baked into the scene (debug gizmos, transient props). Entities your entrypoint.luau spawns already get this automatically (see the entrypoint section) — so reach for setTemporary mainly for things you spawn outside the entrypoint. Everything else you place is saved.
Play is where this changes. A write to /zero/source while play is running lands on the play shadow, live in the session, and a guarded play-exit discards it unless it was kept. vfs.promotePlayShadow(path), or a list of paths, settles them onto canonical source with play still running, and vfs.write(path, bytes, { durable = true }) skips the shadow altogether, which is the route a running simulation writing its own state wants. The core/vfs guide has the model and what each route costs.
Authoring a scene
asset.create("scene", "Lobby") -- → /zero/source/Lobby.scene/ (scene.json + entrypoint.luau + README.md)
A new scene starts as a "spawns" scene with the canonical PlayerPrototype + PlayerSpawn structure already in place, so it boots into a playable player + camera. For a UI-only screen, set its player intent to "none" and author a Camera entity instead. Set the world's startup scene in .world_settings so the world boots into it.
Finding the rest
asset.list("scene") lists the scenes this world can reference; asset.inspect("<name>") summarises one. layers, players, and camera are authored modules under modules/api/engine/ — read them for the full surface. The player/avatar and edit-vs-play model are covered in the components and engine guides.