Scenes, authored as code
Lobby.scene/
build.luau what the scene is made of
scene.json the entities, as the last build left them
entrypoint.luau what happens while the scene is played
The code runs while you author, and saving the scene bakes what it created into
scene.json. That is what makes the entities durable content: a collaborator
opening the world sees them, they replicate, and they load without build.luau
running at all.
The builder is ordinary engine code
function content()
for i = 0, 4 do
local crate = entity.spawn("crate")
crate.localPosition = { i * 2, 0.5, 0 }
crate.component.add("Model", { model = asset.resolve("cube", "mesh") })
end
end
Real loops, real conditionals, real locals, a require of a module that
computes a layout — entity.spawn, component.add and transform writes are the
same calls they are anywhere else.
Modelling what the scene holds
The quick geometry nouns are globals in a build.luau and a .sceneModule's entry script: Group and
Mesh, geometry constructors (BoxGeometry, CylinderGeometry,
LatheGeometry, ExtrudeGeometry, TubeGeometry, LoftGeometry, ...),
modifiers that reshape them (:round, :taper, :bend, :subtract, ...),
MeshStandardMaterial and motion written as a formula of Time:
function content()
local stone = MeshStandardMaterial({ color = "#9a9183", roughness = 0.9 })
local wood = MeshStandardMaterial({ color = "#6b3f2a", roughness = 0.8 })
local well = Group("well")
well.position:set(4, 0, -3)
-- a round wall: its cross-section turned about the vertical axis
well:add(Mesh(LatheGeometry({ { 0.7, 0 }, { 0.95, 0 }, { 0.92, 0.8 },
{ 0.72, 0.8 }, { 0.7, 0 } }, 24), stone, "wall"))
for i, x in ipairs({ -0.85, 0.85 }) do
local post = Mesh(BoxGeometry(0.1, 1.9, 0.1):round(0.02), wood, "post" .. i)
post.position:set(x, 0.95, 0)
well:add(post)
end
local roof = Mesh(ConeGeometry(1.3, 0.7, 4):round(0.04), wood, "roof")
roof.position.y = 2.2
roof.rotation.y = math.pi / 4
well:add(roof)
end
A crate, a chair, a wall or a whole room written this way reads as the thing
it is, where a Model naming a built-in mesh (cube, sphere) draws one
plain shape. At the end of the build the tree is stored in the scene as data
and drawn by one Generator.
guides { path: "systems/quickGeometry/documentation/quickGeometry" } lists
every noun, and the modeling skill covers making an object.
What the builder's code can reach
Everything the engine offers a script anywhere else. The builder's chunk is
compiled into its own environment, which is where inputs lives and is what
gives a placement's params their meaning, and where build lives — the build's
own surface, whose build.asset makes the assets the content names. A module
that joins the script's context with --!context sceneBuild sceneModule in its
leading comment block adds its exports to that environment, and the language
server knows them there; asset.context(path) lists the modules a script's
context holds. Every other name resolves through that environment to the
engine's global one. entity,
asset, Transform, math, require, vfs, task, tools, world,
string, table, os, Field and NoSync read inside a builder as they read
at the top level.
So Transform.quatFromAxisAngle(ax, ay, az, angle) is the same call in a
builder that it is outside one, and require("@builtin::modules.json") loads
the same module — reach for the engine's own maths and modules rather than
rewriting them locally. A toolbox is reached the way it is everywhere:
tools.use("wld", "mode").
The builder authors; components behave. A machine's frame, its housing and its colliders are construction, so they belong in the builder; the component that drives the machine is runtime logic, so the builder attaches it and it runs at play.
The two surfaces
function content()
-- the scene's own entities. Present in play.
end
function editorOnly()
-- present while authoring, absent in play
local guide = entity.spawn("origin_marker")
guide.component.add("Model", { model = asset.resolve("cube", "mesh") })
guide.localScale = { 0.1, 4, 0.1 }
end
content() holds everything the scene is — whatever a player would find there,
lighting and the player setup included. editorOnly() holds whatever should be
present while authoring and absent in play; those entities carry the
EditorOnly participation the runtime deactivates and hides when play begins,
and they are baked too, so a collaborator opening the world sees the same ones.
An alignment guide, a spacing marker or a debug volume is the shape that usually
takes.
Either one on its own is a whole build. Both are declared as globals of
build.luau — function content() … end — which is the name the build reads
them by; a build.luau that declares neither says which two it looked for. A
scene with no build.luau has no build at all.
Editing the file rebuilds the scene
A rebuild never reverts a hand edit. Saving build.luau rebuilds the scene,
and that rebuild, like every plain :build(), keeps each value an author
changed since the last build and reports it under kept; only
layers.active.asset:build({ restate = true }) lands what build.luau states
over those edits (see "What a rebuild touches" below).
Writing build.luau is the signal — save the file and the loaded scene is
rebuilt in place. An entity keeps the id it had, so a reference to it survives:
a spawn naming a prototype, a component field naming another entity, a selection
in the editor. A reference the build writes names the entity the build placed
wherever the field holds it: a Field.entityRef field (a Joint's connected
naming the body it joins, a constraint's targetEntityId, a SkinnedModel's
skeletonRoot, a camera behaviour's target), an element of a Field.list, or a subfield of a
Field.struct (a soft body's attachments[i].target naming the chassis it is
held to). A field declared Field.string is text,
and an id written into one keeps the id the entity had while the build ran, which
names nothing once the build lands: a component of your own that names another
entity declares that field Field.entityRef. Add a sixth crate to the loop above
and the other five stay exactly where they are.
The build writes its own name and each entity's place in the hierarchy onto the
entity, and scene.json records that pair — which is why a rebuild in a later
session, after a reload, lands on exactly the entities the first build placed
without anything having been remembered in between.
A write_file or edit_file of build.luau, and an engine bash command
that writes it (cp, a redirect, sed -i), answers once the rebuild it
started has finished (up to 10 s; a longer one is named under startedWork on
the answer and its notice arrives on a later call). A write made in an agent's
sub-client waits as well for the rebuild it starts in the user's client, so the
notice on its answer is that write's own. What the rebuild landed
comes back with that answer as a notice naming the scene and the count each
surface placed:
[info] a write to build.luau rebuilt the scene { content="5", scene="scenes.main",
editorOnly="1" }
When the scene holds anything build.luau does not state, the notice counts
it, and its message is the first line of the build's own message, which
counts every list and names the call that lands the build's values:
[info] a write to build.luau rebuilt the scene { content="40", kept="2",
handPlaced="1", scene="scenes.main", message="build.luau against the scene:
kept 2 values on 2 entities (crate_3, lamp_2); driven 0 fields; hand-added 0
components or attributes; hand-placed 1 entity (photo_camera). A plain rebuild
never reverts a kept value; `layers.active.asset:build({ restate = true })`
lands build.luau's." }
A big scene takes seconds to rebuild, and an edit saved during one of those is an edit to code the rebuild has already read. It gets a rebuild of its own once that one finishes, and says which it was:
[info] a write to build.luau arrived during a rebuild and was rebuilt after it
{ content="6", scene="scenes.main", editorOnly="1" }
Several edits saved during the same rebuild get the one run after it, which reads the file as it stands then — so it carries all of them.
A rebuild notice describes the scene as that rebuild left it, and it reaches
you only while that rebuild is the scene's latest build. A later build of the
scene, a :build() call or the rebuild of a later write, takes back every
notice of the builds before it that you have not read yet. So the order you
read them in is the order they ran in: a rebuild notice that arrives after a
:build() answer is a rebuild that ran after that call, and the scene holds
what the notice says.
A scene that declares a build also runs it when it loads in edit, so the scene
shows what the code says now, including an edit made while the world was closed.
A .sceneModule the build places is part of that: the build writes what each
placement builds into scene.json beside the placement, and a load in edit
after one of those modules changed runs the build again.
Play mode never runs it — in play the entities are loaded from scene.json as
authored content.
When the file did not change
:build() runs the build against what it resolves right now — for the case
where something the builder reads changed and the file did not: a module it
requires, an asset it resolves, a value it computes from elsewhere in the world.
After a write it is unnecessary; the write has already run it.
layers.active.asset:build() -- rebuild and save
layers.active.asset:build({ save = false }) -- rebuild, leave the result unsaved
A build with { save = false } lands in the live scene, and what it changes is
among the scene's unsaved edits until a save. A build that changes nothing
leaves none: on a scene that already holds what build.luau states (the values
it keeps included, below) it writes nothing, so it is the way to ask the build
what it would keep without leaving anything to save.
It answers with how many entities each surface placed — { content = 5, editorOnly = 1 } for the two above — and with nil for a scene that has no
build.luau. Called while a build for that scene is already running, it comes
back at once with that build instead of starting a second one:
{ inFlight = true, scene = "/zero/source/scenes/main.scene", trigger = "write",
startedBy = "a write to build.luau",
message = "a build of /zero/source/scenes/main.scene started by a write to
build.luau is running now — this call answered with it and started
no second build" }
inFlight is what tells the two answers apart.
Stable placement keys
Give a placement a key when its name, parent or order may change:
function content()
local chair = build.key(entity.spawn("Reception chair"), "reception/chair")
chair.localPosition = { 2, 0, 4 }
chair.component.add("Model", { model = asset.resolve("cube", "mesh") })
end
The key identifies that placement within its build surface and target. Renaming, reparenting or reordering it retains its entity id. A repeated collection uses keys from its data, such as a room id or item id.
Assigning the first key to an existing placement preserves the entity at its
current hierarchy/name key. Changing an explicit key creates a new placement.
Duplicate keys are refused before the existing build changes. A tool can read
the key through require("@builtin::assetTypes.scene.shared.build").identityOf(id).
Generated content and recorded edits
A rebuild produces a new baseline and composes recorded edits over it. Moving a generated object records its authored position; deleting it records its removal. Objects placed outside the builder remain part of the authored scene. Stable placement keys let these edits follow their objects across rebuilds.
The Scene changes panel compares authored content with the generated baseline.
Saved means the recorded edits are durable; they remain listed because they
still differ from build.luau. scene.json is the composed output. Review
recorded edits through sceneAuthoring.reviewRecorded; its result includes
conflicts that require an authoring decision.
Exposing editable source inputs
A builder can bind a source argument to the placements it controls. The binding
records the source revision, exact argument range and affected entity IDs.
build.source() supplies the source snapshot; SourceEditing.calls locates
arguments, SourceEditing.bind describes the input, and build.bindSource
registers it. The binding's outputs are live entity IDs (item.id), while
build.key supplies the stable placement identity used across rebuilds.
Read man SceneBuild/buildSurface and man SourceEditing for the binding
signatures and examples. Then use sceneAuthoring.reviewSources to obtain
editable inputs and their review receipt. Pass that receipt, the input owner
and ID, its complete output list and a replacement expression to
sceneAuthoring.replaceSource. It checks the reviewed revision, updates the
source and rebuilds while retaining recorded edits. A shared input names every
placement it affects; a placement-specific input names that placement alone.
Every entity a build places records what that build stated about it, property
by property and component by component. A rebuild compares the code's
statement with that record: a property the code now states differently is
written, and one it states the way it did last time is left as the scene holds
it, so a value an author changed since (in the inspector, through a tool, from
execute) survives the rebuild. The build's answer names every value it left
that way where the code states another, under kept:
{ content = 40, editorOnly = 0, saved = true,
kept = { { entity = "ent_0a1b2c3d4e5f6071", name = "crate_3",
property = "p", stated = "2,0,4", held = "3,0,4" },
{ entity = "ent_1c2d3e4f5a6b7c8d", name = "lamp_2",
property = "c:@builtin::components.Light", field = "castsShadows",
stated = "true (default)", held = "false", unstated = true }, ... } }
property is the build's short code: n name, i internal flag, p
position, r rotation, s scale, o active flag, m lifecycle mode
(participation), w replication scope (network scope), y synced flag, e
the whole entity, a:<name> an attribute, c:<type> a component (with
instance and field). The message spells each one out
(crate_3 (ent_0a1b2c3d4e5f6071) position: the scene holds 3,0,4, build.luau states 2,0,4). A rename is a kept n: the entity is the same one, under the name
the scene gave it.
kept covers every field of a component the code states, the fields the code
leaves out included: lamp_2 above is a light whose shadows were switched off
in the inspector, where build.luau adds the light without saying anything
about shadows. Such a field is marked unstated, and its stated is the
component's declared default, which is what the code's statement gives it. An
entity added by hand is never in kept: it is always under handPlaced
(below), however much it looks like part of the build.
These are every value a build can state about an entity it placed: its name,
internal flag, transform, active flag, lifecycle mode, replication scope,
synced flag, attributes and components. An entity's render layer and its
hide() / show() switch are values no build states (a build setting one is
refused); the components a build places set them at runtime, a player rig's
render layer among them, so the lists leave them out. The report states what
the scene holds on both instead, over the entities a build placed:
renderLayers names each one on a layer other than the default, with the
layer ({ entity, name, layer }; scene.json saves the layer with the
entity), and hidden names each one hide() holds hidden ({ entity, name };
scene.json does not save it, so a load shows every entity until a component
hides it). The message's third line counts both:
On the 12 entities a build placed: render layer set on 1 (sign_1 (ui)), which
scene.json saves with each; hidden by hide() 1 (crate_4), which scene.json
does not save.
The report also says where it read the scene. Each client of the world (the
user's editor, and each agent's sub-client) holds its own live scene and its
own unsaved edits, and a build compares the scene of the client it runs in.
client names that client (user, or the sub-client's id), and unsaved
lists the edits its scene held beyond the saved scene.json when the build
compared it (the entries sceneAuthoring.changes lists, { entity, name, kind, builtBy? }), so a report reads as a statement about scene.json exactly
when unsaved is empty. An unsaved edit the scene records (a move, a rename, a
render layer, a component field) reaches every client of the world, so a
sub-client's report lists the user's unsaved edits once they have arrived; a
hide() stays in the client that called it, so hidden is that client's
own. The message's fourth line states both:
Compared in the user's client (`user`), against a scene holding 1 unsaved edit
beyond scene.json (crate_5); `sceneAuthoring.changes` lists them.
To land what the code states over what the scene holds, build with restate.
It lands every stated value and puts every unstated field of a stated
component back to its default:
layers.active.asset:build({ restate = true })
A restate writes exactly what kept names. A number the scene holds within
the precision a saved record keeps (a rotation a play and edit round trip moved
in its seventh decimal) is no kept value, and a restate leaves it as the scene
holds it. Neither is the bookkeeping a component writes about its own runtime
(an avatar's map of the bones it expanded into), so a restate leaves that
component running as it is. The scene.json diff after a restate is the
kept list and nothing besides.
Some component fields are written at runtime by another component: a
ProceduralSky with syncSunToLight orients the scene's sun light and sets
its colour and intensity from its timeOfDay. Such a field holds what that
component wrote, so a rebuild leaves it to that component every time,
restated or not, exactly as a load of the scene does: the light stays where
the sky put it. The answer names each one the build states another value
for under driven, apart from kept, because it is no edit to the scene:
driven = { { entity = "ent_2d3e4f5a6b7c8d9e", name = "sun_light",
property = "c:@builtin::components.Light", field = "directionY",
stated = "-0.75", held = "-0.21",
drivenBy = { component = "ProceduralSky", entity = "ent_3e4f5a6b7c8d9eaf", name = "evening_sky" } }, ... }
What the code states nothing about is the scene's, and no build touches it, restated or not. The answer names all of it, so one answer covers everything the scene holds besides the build:
handAdded: a component or an attribute added by hand to an entity the build placed, which no build stated ({ entity, name, property, instances?, held? },propertybeingc:<type>ora:<name>).handPlaced: an entity no build placed (one an author dragged in, a tool placed, a script spawned), each with its components; an entity under one of them comes with it ({ entity, name, property, components },propertyalwayse, the whole entity).
handAdded = { { entity = "ent_4f5a6b7c8d9eaf0b", name = "crate_5",
property = "a:inspected", held = "true" }, ... },
handPlaced = { { entity = "ent_5a6b7c8d9eaf0b1c", name = "photo_camera",
property = "e", components = { "Camera", "LookAtConstraint" } }, ... }
Every entry of all four lists carries entity, name and property, so one
reader walks them alike; each list adds what tells its entries apart:
| List | Entry | property |
|---|---|---|
kept | { entity, name, property, instance?, field?, stated, held, unstated? } | n, i, p, r, s, o, m, w, y, a:<name> or c:<type> |
driven | { entity, name, property, instance?, field, stated, held, drivenBy } | c:<type> |
handAdded | { entity, name, property, instances?, held? } | a:<name> or c:<type> |
handPlaced | { entity, name, property, components, builtTwin? } | e |
for _, list in ipairs({ report.kept, report.driven, report.handAdded, report.handPlaced }) do
for _, entry in ipairs(list or {}) do
print(entry.name .. " " .. entry.property)
end
end
The message spells a handPlaced entry's code out the way it spells the
others: photo_camera (ent_5a6b7c8d9eaf0b1c) whole entity: Camera, LookAtConstraint.
To make one of these part of the build, delete the hand-made one and save the
scene (layers.active.asset:save()), then write it into build.luau. A write
to build.luau rebuilds the scene at once in every client, and the client the
write was made in saves its rebuild, so the delete has to be in the saved scene
or in that client's scene before the write: a delete left unsaved in another
client (the user's editor, when the write comes from a sub-client) can reach
the writing client after its rebuild saved, and the hand-made one comes back.
Stating it first places the build's copy beside the hand-made one. When that
happens, the hand-made entry carries builtTwin, the id of the entity the
build placed under the same name, the message names the calls that settle it
(delete the hand-made one, then save), and the summary line counts it
("hand-placed 3 entities (...), 1 of them a second copy of an entity
build.luau places under the same name").
Every answer carries a message. It opens with one line counting all four
lists and naming the entities they are on, a line saying what the lists
compare (the values above, and that render layers and hide() / show() are
runtime state no build sets), the line counting render layers and hidden
entities, the line naming the client and its unsaved edits (both above) and a
line comparing build.luau against scene.json as saved, then names the first
entries of each list. The saved line names each unsaved edit and what it
changed, since scene.json holds the value from before it ("Against
scene.json as saved: the lists hold for it everywhere but where an unsaved edit
changed the scene, and there scene.json holds the value from before the edit:
stall_3_canopy (Model.material plastic_red -> gold)."), and it names the
entities whose live state differs from the scene's files with no unsaved edit
behind the difference: a write to those files this client's live scene has not
taken. The scene records such a live value among its unsaved edits, so a save
from that client writes it over scene.json; the line names the calls that
take that client's live scene back to scene.json first, a
discardSceneEdits of those entities and then
tools.use("scene", "reload", "<scene>"). The answer carries the count as
behindFiles. Its
first line reads:
build.luau against the scene: kept 2 values on 2 entities (crate_3, lamp_2);
driven 7 fields (sun_light); hand-added 1 component or attribute (crate_5);
hand-placed 1 entity (photo_camera). A plain rebuild never reverts a kept
value; `layers.active.asset:build({ restate = true })` lands build.luau's.
So one build({ save = false }) answers "does build.luau describe this
scene" whole: an empty kept, handAdded and handPlaced mean the scene
holds what the code states and nothing besides (driven is the runtime's,
never an edit). SceneBuild.drift() reads a narrower part of the same
question, the entity's own values (name, internal flag, transform, active flag,
lifecycle mode, replication scope, synced flag and attributes) of the entities
a build placed, with the precision the build reads kept with; the report is
the whole answer.
Every client of the world that holds the scene (the user's editor and each
agent's sub-client) runs its own rebuild of a write to build.luau, against
the values its own scene holds. A restate in one client lands build.luau's
values there and saves them into scene.json, and every other client holding
the scene takes from that save, as it applies the save, every value a scene
record carries: the name, the transform, the lifecycle mode, the replication
scope, the attributes and the component fields, an asset a field names among
them. A client that has not taken a save holds the values from before it, and
its own report says so: its saved line names those entities and the calls
that take that client back to scene.json. Its next save writes them back
over scene.json, so run those calls there first. A
report-only build in a client that took the save keeps nothing.
The synced flag decides how a load spawns the entity, so another client takes
it when it next loads the scene, and the active flag stays in the client that
restated it.
An operation the bake cannot hold is refused
The rule is one sentence: a build accepts an operation exactly when a scene record carries its result. A record describes an entity's lifecycle, its place in the hierarchy, its name, its transform, its visibility, its active state, its attributes, its participation mode, its network scope, whether its live state replicates, and the script components it carries with their public data — so those are what a builder may do. An operation writing anything else would be live during the build and absent the next time the scene loaded, so it is refused instead of applied.
The set is an allowlist, which means an operation the bake has not learned to carry is refused rather than quietly permitted. A gap is loud instead of invisible.
A refusal names the operation, the entity, and the build it answered to:
this operation cannot be captured into a scene build, so it is refused rather
than applied and then lost: EntityDuplicate. ...
The capture scope refusing it is scope 9, opened at:
[C] function capture
...
/zero/source/tmp/Orchard.sceneModule/init.luau:5
a build may only mutate the entities it creates, and 'ent_ecb63dd39a782b25'
(the entity named 'Bram') is not one of them, so entity.localPosition is
refused rather than applied and then lost. ...
A lookup by name inside the builder finds the build's own entities first.
entity.find("Bram") after a spawn of Bram (by the builder, or by a module it
called) is that spawn, even when the world around the build holds another
Bram, and entity.findAll("Bram") lists the build's own ahead of the
world's. The world's entities stay readable after them; they are the ones a
build may read and not change.
The second rule reaches the components of an entity the build did not create:
a field write such as component.get("Light").intensity = 2, an enabled
write, setField, a method of the component that writes its own state, and a
tool that patches an existing entity (lighting.setup on the scene's sun) are
each refused the same way, before they land.
A field holding a table answers a read with that table, so a change made in it
(ref.items[1] = 5, ref.offset.x = 2) reaches the field without assigning
it. On an entity the build did not create, such a change is judged when the
build closes, however the builder came to hold the table: read inside the
build, handed out by a walk of the component (for k, v in ref), or read,
walked or assigned before the build opened and held since. The table is put
back as it stood before the build changed it, and the change joins the
refusals entity.capture hands back, named "the change made in place to the
table ... holds". A component the builder attaches runs its own lifecycle
inside the build, and a field table that lifecycle reads is its own to change
while it runs: what the lifecycle changes in it stands, and the builder's own
changes to it, before the lifecycle ran and after it returned, are judged.
So try it. If you do not know whether the build can hold something, write it and run the build — a refusal costs nothing. The refused call never lands, the build is abandoned whole rather than baked with a difference, the previous build stays in the scene exactly as it was, and nothing the builder did before the refusal is half-applied. You learn the answer in one rebuild, by name, and the scene is where you left it.
A runtime resource is the one refusal with an answer inside the build:
renderer.mesh.create makes a GPU mesh that lives as long as the session, which
no record can hold, and the same geometry made as an ASSET is held by every
record that names it. That is build.asset, below. Everything else a refusal
names goes outside the builder, or into a component the builder attaches, which
runs at play.
Placing an asset that expands into a hierarchy
Instantiating an asset that expands into a hierarchy is a capturable operation.
There are two ways to place one, and they bake differently. ProbeTree below
stands for any such asset.
Instantiate it directly and its whole hierarchy becomes the scene's own entities:
function content()
local grove = entity.spawn("grove")
asset.resolve("ProbeTree"):instantiate(grove)
end
Every entity of the asset lands as a record naming the build that placed it and its own place in the hierarchy, with its components baked in:
buildOwner=build buildKey=grove Model
buildOwner=build buildKey=grove/probe_child Model
They are the scene's content from then on: selectable, movable, individually saved, and unaffected by a later edit to the asset.
Attach an Asset component and the placement stays linked to the asset:
function content()
local slot = entity.spawn("tree_slot")
slot.component.add("Asset", { source = "ProbeTree" })
end
The record holds slot and its Asset component. The asset's own entities are
spawned by that component wherever the record lands, as temporary children, so
they are not records themselves — which is the general rule for anything a
component the builder attached creates: the record names the component, and the
component produces its subtree again on every load. Editing the asset updates
every placement.
Reach for the first when the result is this scene's content and you want to shape it here; reach for the second when the asset is the source of truth and the placements should follow it.
An entity whose live state replicates
The world is always multiplayer, and a scene says per entity whether its live
state is shared or local. entity.spawnSynced is that statement in a builder:
function content()
-- Everyone sees the same door, and the peer that opens it opens it for
-- everybody.
local door = entity.spawnSynced("vault_door")
door.component.add("Model", { model = asset.resolve("cube", "mesh") })
-- A plain spawn is LOCAL: every peer gets one from `scene.json`, and a
-- change one peer makes to it stays on that peer.
local torch = entity.spawn("torch")
end
The record carries it and scene.json records it, so it survives the bake and
the reload. At play the room creator spawns the synced entities and a joiner
receives them off the relay snapshot instead of spawning its own — which is why
one peer opening the door does not leave five doors standing.
A build is authoritative over this the way it is over everything else it places:
change spawnSynced back to spawn and the rebuild makes the entity local
again, keeping its id.
The assets a build makes
Some of what a build states is not an entity but an ASSET: a mesh a lathe
produces, a texture a pattern writes, a material a palette picks. build.asset
is how a build makes one.
function content()
local tower = build.asset("mesh", "tower", function()
local positions, indices = lathe({ { 2, 0 }, { 1.6, 4 }, { 1.4, 9 } }, 16)
return { positions = positions, indices = indices }
end)
local e = entity.spawn("tower")
e.component.add("Model", { model = tower })
end
The three arguments are the asset TYPE to make, the NAME to make it under, and
the function that PRODUCES it — which takes nothing and returns the same
creation parameters asset.create takes for that type. The call hands back the
asset's AssetRef, which is what a component field names, so the scene saves a
reference to a durable asset rather than to something that existed only while
the build ran.
The producer runs when the build script changed, and never otherwise. The
asset is authored inside the build's own folder — Lobby.scene/tower.mesh —
and the build records which version of build.luau produced it:
Lobby.scene/
build.luau what the scene is made of
tower.mesh the asset that build makes
.build.assets which build.luau produced it
scene.json the entities, as the last build left them
So the scene reloads without re-authoring anything, and editing the lathe
profile re-authors tower.mesh in place: same path, same guid. That is the
part that matters — scene.json references assets by guid, so a Model naming
tower on Monday still names the tower the code produces on Friday.
A .sceneModule makes assets the same way, into its own folder, keyed on its
init.luau.
Producing is keyed on the whole script, so editing anything in build.luau
re-authors every asset it makes. That costs a build; it never costs a
reference.
Any asset type, not just meshes
The first argument is the type, and the producer returns whatever
asset.create takes for THAT type — so the material a generated mesh is drawn
with is itself something the build makes:
local stone = build.asset("material", "WallStone", function()
return {
shader = "pbr",
properties = {
base_color = { 0.62, 0.60, 0.55, 1 },
roughness = 0.85,
metallic = 0,
},
}
end)
e.component.add("Model", { model = wall, material = stone })
A material's overrides go in one properties table, colours as
{r, g, b, a} arrays. mat.yaml groups them on disk under floats:,
colors:, ints: and bools:, and reading a material file makes those look
like creation keys — they are not, and passing one is refused with the shape to
use instead.
The producer owns what it makes
A generated asset is the build's output, so the build is the only thing that writes it. Editing one at runtime — setting a property or a texture on the live material, hand-editing its files — puts it in a state the next produce does not know about, and what the code says no longer describes what is on disk. Change the producer and rebuild; that is the whole edit loop, and it is why the producer runs again exactly when its code changes.
sceneModule — a part of a scene, reused
A whole scene is one build.luau. A .sceneModule is the same idea for a part
of one: a folder whose init.luau declares the inputs a placement may set and
returns the builder.
inputs = {
count = Field.number(3, NoSync),
spacing = Field.number(1.5, NoSync),
}
return function()
local root = entity.spawn("colonnade")
for i = 1, inputs.count do
local pillar = entity.spawn("pillar_" .. i, { parent = root })
pillar.localPosition = { (i - 1) * inputs.spacing, 0, 0 }
pillar.component.add("Model", { model = asset.resolve("cube", "mesh") })
end
end
inputs follows the component public convention exactly — the same Field.*
constructors, declared as a global the way a component declares public. A read
of inputs.<name> inside the builder is the resolved value for the placement
being built: the param that placement set, else the declared default. Reading a
name the module never declared raises and lists the ones it does:
sceneModule: this module declares no input 'nosuch' (declared: count)
Place one with the SceneModule component:
local place = entity.spawn("colonnade_0")
place.component.add("SceneModule", {
source = asset.resolve("Colonnade", "sceneModule"),
params = { count = 4, spacing = 2 },
})
A scene's build.luau places one with the same two lines, which is how a row of
slots each carrying its own variant is written as a loop. The placement is what
the scene's build describes; the entities under it belong to the placement, which
lands them again wherever the placement goes — so the scene holds one copy per
placement however many times either is rebuilt.
What the builder made lands in the scene as ordinary entities — named,
selectable, movable, saved in scene.json, replicated. The folder holds no
baked artifact; the scene holds the output. Placing the same module twice with
different params gives two different results from one asset, each with ids of
its own.
Changing a placement's params, or editing init.luau, re-runs the builder for
every placement and reconciles the result the same way a scene build does — same
entities, same ids, updated contents. A placement whose build already matches
its module and params changes nothing when the scene loads or the mode flips. A
module edited while the scene was closed is built again when the scene next
loads, and the load shows what that build adds, changes and stops placing. A
build that runs as its scene loads reruns on every load, so it records nothing in
the scene's unsaved edits; play of an editor session builds the placement from
the module too, and the next save writes the build into scene.json. A load-time
build that states no records over entities the placement built before leaves
those entities and warns. :rebuild() on the component forces a build for a
change nothing else reports:
place.component.get("SceneModule"):rebuild()
A rebuild that cannot run raises with the reason (no module bound, a source that is not scene-instantiable, a builder that raised), and the previous build stays in the scene.
Who states a placement's params
A placement an author made holds its own params — spawn it, set them, and they are yours.
A placement a build.luau made is stated by that build.luau. The build names
the placement's source and params and states them again on every run, and
writing build.luau is what runs it. Setting a
param on such a placement rebuilds it at once, and the value holds until the next
run of the build, which states the params its own source gives — so it is a
preview of what the build would say, and the file is where to change it for good.
Both ends of that say so. Setting the param names the file that states it:
[warn] [client user] a build placed this entity and states its SceneModule params — a param
set on the placement holds until that build runs again and states them from its
own source { placement="tent_ring_placement", set="count = 9",
statedIn="/zero/source/scenes/main.scene/build.luau (content)" }
and the run that states them again names what it replaced:
[warn] [client user] a build ran and stated this placement's SceneModule params over the ones
set on the placement — the file the build is written in is where they are stated
{ placement="tent_ring_placement", replaced="count: 9 → 7",
statedIn="/zero/source/scenes/main.scene/build.luau (content)" }
A run that states what the placement already holds says nothing, and a placement
an author made is never stated by any build. The same holds for a placement one
.sceneModule builder makes inside another: its init.luau is the file named.
Ask a module about itself without touching a scene:
local m = asset.resolve("Colonnade", "sceneModule")
m:inputs() -- { { name = "count", kind = "number", default = 3 }, ... }
m:build({ count = 2 }) -- run the builder, return the records, scene untouched
Which one to reach for
- One arrangement, belonging to one scene — its lighting, its layout, its player
setup: the scene's own
build.luau. - A thing several scenes place, or one scene places many times with different
settings: a
.sceneModulewith the settings asinputs. Copies that differ only in where they stand (four chairs round one table) can also be one quick geometryGroupin the scene's own build,:clone()d for each.
Both produce the same kind of result — real entities in the scene, baked and
replicated — so a piece of a build.luau that starts appearing twice moves into
a .sceneModule with no change to what the entities are.
Related
guides { path: "core/scenes" }— loading, saving, layers, the player intent and the live players registry.guides { path: "types/scene" }/guides { path: "types/sceneModule" }— the two asset types' own references.guides { path: "core/components" }— the behaviour a builder attaches.