Kit Piece
Updated
Places one piece chosen from a modular building kit.
- Type
ent-kit-piece- Script class
KitPieceMeshEntity- Family
- Meshes
Overview
Section titled “Overview”A Kit Piece shows one part of a modular building kit. A kit is a single glTF file that holds many architectural parts (walls, floors, doorways, stairs, roof sections), each tagged with an id. A Kit Piece loads just the part named by its pieceId, so a whole house can be assembled from one file, piece by piece.
Kit pieces are placed from a catalog of kits, so they are not offered in the editor’s Add menu as an empty entity. Once placed, a Kit Piece behaves like any model entity: its required Kit Piece loader component (comp-kit-piece) names the file and the piece, and it draws with the kit’s materials. Unlike other models, a new Kit Piece starts with a Shadow component that both casts and receives shadows, which suits walls and floors.
When the piece is in place, the loader sends KitPiece::ready. When it cannot load, it sends KitPiece::error with a message: a pieceId that matches no part, or more than one, is an error, and the loader never falls back to the whole kit. Both events reach scripts through a Signal Emitter on the entity. Only the animation tracks that target the chosen part are kept.
A Kit Piece is architecture, not a character: it does not take the Character Controller, the Steering components, the NavMesh Agent, Billboard, Grass, Grass Bender or Don’t Unload. For a free-standing model, use a Mesh Gltf.
What matters most:
src(Kit Piece loader): the kit file, as a project asset reference (ASSET-<uuid>) or a URL.pieceId(Kit Piece loader): which part of the kit to show.castandreceive(Shadow): both on by default for a piece.- Colliders and Navmesh Walkable or Navmesh Collidable, if you add them, make pieces solid and part of the navigation mesh.
Set it up
Section titled “Set it up”- Place a piece from a kit in the catalog (see Scenes and hierarchy): kit pieces are not in the Add menu. The placed piece names its kit in
srcand its part inpieceId. - Move and turn it into place next to the other pieces, and name it, for example
North Wall. - Add a collider so players cannot walk through it, and a Navmesh component if characters navigate the building.
- Add a Cache Mesh to pieces you repeat many times, so identical copies share one draw call.
- Add a Signal Emitter with a signal to follow its loading from a script.
Examples
Section titled “Examples”Catch a wrong piece id
Section titled “Catch a wrong piece id”Goal: warn clearly when a piece cannot load, for example after a kit was updated and a part was renamed.
The piece North Wall has a Signal Emitter whose signal is north-wall.
#pragma lifecycle(startup)
function startup() { const piece = findEntity('North Wall'); const loader = piece.getComponent(KitPieceComponent);
on('north-wall', ({ eventType, data }) => { if (eventType === EventType.KitPiece.Ready) { log('Loaded piece', loader.props.pieceId); } if (eventType === EventType.KitPiece.Error) { console.warn(`Piece "${loader.props.pieceId}" failed: ${data.message}`); } });}getComponent(KitPieceComponent)returns the piece’s loader;props.pieceIdis the part it asks for.EventType.KitPiece.Errorarrives when the id matches no part or more than one.data.messagegives the reason.readyis sent again after every reload, so the script also reports later changes.
Open a doorway in a wall
Section titled “Open a doorway in a wall”Goal: when a quest step completes, replace a plain wall with the doorway piece from the same kit.
The piece Vault Wall has a Signal Emitter whose signal is vault-wall, and the kit has a part with the id wall-doorway.
#pragma lifecycle(startup)
const DOORWAY = 'wall-doorway';let previous = '';
function startup() { const loader = findEntity('Vault Wall').getComponent(KitPieceComponent);
on('quest/vault-opened', () => { if (loader.props.pieceId === DOORWAY) return; previous = loader.props.pieceId; loader.setProps({ pieceId: DOORWAY }); });
on('vault-wall', ({ eventType, data }) => { if (eventType === EventType.KitPiece.Ready && loader.props.pieceId === DOORWAY) { emit('vault/doorway-ready'); } if (eventType === EventType.KitPiece.Error && loader.props.pieceId === DOORWAY) { console.warn('No doorway piece: ' + data.message); loader.setProps({ pieceId: previous }); } });}- Another script calls
emit('quest/vault-opened')when the player completes the step;onreacts to it. setProps({ pieceId })asks the loader for another part of the same kit file;srcstays the same.- When the doorway is in place,
emit('vault/doorway-ready')tells other scripts, for example to play a sound or enable a trigger. - If the kit has no such part, the script logs the reason and asks for the previous piece again.
- An id that matches more than one part is an error too: keep piece ids unique within a kit.
- A Kit Piece cannot carry Grass. To grow grass on the ground, use a Floor, a Primitive Mesh, a Terrain or another model entity.
ModelLoaderComponentalso finds a piece’s loader, which helps scripts that work on any model.
Components
Section titled “Components”What a new Kit Piece is made of. Required components are always present and cannot be removed; the others can. Per entity says whether an entity can hold one of that component or several. Layer, Lock and Enable are on every placed entity, and Transform holds its position, rotation and scale.
| Component | Type | Role | Per entity | What it does |
|---|---|---|---|---|
| Layer | comp-layer |
Required | One | Puts the entity on a render/raycast layer so cameras and rays can include or skip it. |
| Lock | comp-lock |
Required | One | Editor-only flag that stops the entity from being selected or moved. |
| Enable | comp-enable |
Required | One | Turns the entity and its children on or off: hides them and stops their behavior. |
| Shadow | comp-shadow |
Starts with | One | Lets the entity’s meshes cast and/or receive shadows from lights. |
| Kit Piece | comp- |
Required | One | Places one piece chosen from a modular building kit. |
| Transform | comp- |
Required | One | Position, rotation and scale of the entity, with optional editor-only per-axis locks. |
You can also add 46 optional components, such as Animation Clip, Animation Graph, Animation Timeline, Attribution, Basic Material, Box Collider.
The settings of a new entity, as the runtime creates it. Change them in the Properties panel of XR Creator, or from a script with getComponent(…).setProps({ … }).
Shadow
Section titled “Shadow”| Prop | Default | Range |
|---|---|---|
cast |
true |
|
receive |
true |
Kit Piece
Section titled “Kit Piece”| Prop | Default | Range |
|---|---|---|
src |
"" |
|
pieceId |
"" |
Events
Section titled “Events”With a Signal Emitter on the entity, these events reach scripts as { entityId, eventType, data }. Compare eventType with the EventType constants.
Shadow::changeKitPiece::readyKitPiece::error
Like every entity, it also reports: Transform::change (and position-change, rotation-change, scale-change), Enable::change, Layer::change and Lock::change.
Live example
Section titled “Live example”Run it in the browser, read its scripts, and download it as an XR Creator project.
A small shrine assembled from one modular kit file: floor tiles, pillars, walls, a beam and steps are each a Kit Piece that loads only the part named by its pieceId. The script counts the pieces as they load.
Orbit around the shrine: every part comes from the same kit file. The log counts the pieces as they load. Drag to orbit the camera, scroll to zoom.
From a script
Section titled “From a script”Find the entity by its name, check its class, and work with its components. Name the entity in the Hierarchy first; this example expects My Kit Piece.
#pragma lifecycle(startup)
function startup() { // Find the entity by the name it has in the Hierarchy. const entity = findEntity('My Kit Piece'); if (!(entity instanceof KitPieceMeshEntity)) return;
// Its Shadow component holds the settings listed under Props. const component = entity.getComponent(ShadowComponent); log(component.props);}