Skip to content

Kit Piece

Updated

Places one piece chosen from a modular building kit.

Type
ent-kit-piece
Script class
KitPieceMeshEntity
Family
Meshes

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.
  • cast and receive (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.
  1. 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 src and its part in pieceId.
  2. Move and turn it into place next to the other pieces, and name it, for example North Wall.
  3. Add a collider so players cannot walk through it, and a Navmesh component if characters navigate the building.
  4. Add a Cache Mesh to pieces you repeat many times, so identical copies share one draw call.
  5. Add a Signal Emitter with a signal to follow its loading from a script.

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.

PieceCheck.jx
#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.pieceId is the part it asks for.
  • EventType.KitPiece.Error arrives when the id matches no part or more than one. data.message gives the reason.
  • ready is sent again after every reload, so the script also reports later changes.

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.

OpenDoorway.jx
#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; on reacts to it.
  • setProps({ pieceId }) asks the loader for another part of the same kit file; src stays 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.
  • ModelLoaderComponent also finds a piece’s loader, which helps scripts that work on any model.

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-kit-piece Required One Places one piece chosen from a modular building kit.
Transform comp-transform 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({ … }).

Prop Default Range
cast true
receive true
Prop Default Range
src ""
pieceId ""

With a Signal Emitter on the entity, these events reach scripts as { entityId, eventType, data }. Compare eventType with the EventType constants.

  • Shadow::change
  • KitPiece::ready
  • KitPiece::error

Like every entity, it also reports: Transform::change (and position-change, rotation-change, scale-change), Enable::change, Layer::change and Lock::change.

Run it in the browser, read its scripts, and download it as an XR Creator project.

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.

KitPieceMeshEntity.jx
#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);
}