Skip to content

Common components

Updated

A few components belong to almost every entity. Transform says where the entity is, Enable whether it is on, Layer which layer it is on, and Lock whether the editor can pick it. Three more are common enough to learn early: Billboard turns an entity toward the camera, Group recenters a group on its children, and Shadow decides whether meshes cast and receive shadows. This page documents each one, with its props, its events and how a script uses it.

  • You know what components are and how getComponent and setProps work. See Components.
  • To hear the events listed here, the entity needs a Signal Emitter. See Events and signals.

Every entity except the scene root is an element. Every element carries three components from the moment it is created, and they can never be removed: Enable, which switches the entity and its subtree on or off; Layer, which puts the entity on a render and raycast layer (see Layers); and Lock, which stops the editor from picking or transforming the entity. Most element types also start with a Transform, which holds the position, rotation and scale. This page documents all four, and the other components almost every entity shares:

Component Type On Script shortcut
Transform comp-transform Most entity types; cannot be disabled setPosition, setRotation, setScale, setLookAt
Enable comp-enable Every element; required setEnabled(on), isEnabled()
Layer comp-layer Every element; required setLayer(n)
Lock comp-lock Every element; required setLocked(on)
Billboard comp-billboard Optional none
Group comp-group Group entities only none
Shadow comp-shadow Optional; default on meshes none

comp-transform holds the entity’s local position, rotation and scale: where it is relative to its parent. It is a live view of the entity’s own position, rotation and scale, so the scene always saves where the entity is now. Most entity types start with a Transform and require it; it cannot be removed or disabled.

Prop Type Default Description
position { x, y, z } 0, 0, 0 Local position, in metres from the parent.
rotation { x, y, z } 0, 0, 0 Local rotation, as Euler angles in radians.
scale { x, y, z } 1, 1, 1 Local scale on each axis.
lockPosition { x, y, z } booleans all false Position axes the editor’s gizmo cannot move.
lockRotation { x, y, z } booleans all false Rotation axes the editor’s gizmo cannot turn.
lockScale { x, y, z } booleans all false Scale axes the editor’s gizmo cannot resize.

There are two ways to move an entity from a script:

  • The setters: entity.setPosition(x, y, z), setRotation(x, y, z) (Euler radians), setScale(x, y?, z?) and setLookAt(x, y, z) (face a world point). They move the entity’s physics body and colliders with it, and send the Transform events. They return the entity, so they chain: door.setPosition(0, 0, 2).setRotation(0, Math.PI, 0).
  • Direct writes: entity.position.x += 1, entity.rotation.y = angle. They are the quickest way, fine for a purely visual object moved every frame. They send no events and leave colliders behind.

Use the setters whenever something else must follow the move: physics, a Signal Emitter listening to Transform events, or networking.

The lock… props guard only the editor’s gizmo: a locked axis does not move whichever handle an author drags. Everything else still sets every axis: the setters, prop edits, scripts, undo, animation and networking. TransformComponent also has lockPosition(locked?), lockRotation(locked?) and lockScale(locked?), which lock (or, with false, unlock) all three axes of one part at once.

Event EventType Data
Transform::position-change EventType.Transform.PositionChange { position }: the new local position.
Transform::rotation-change EventType.Transform.RotationChange { rotation }: the new local rotation, Euler radians.
Transform::scale-change EventType.Transform.ScaleChange { scale }: the new local scale.
Transform::change EventType.Transform.Change { changed }: after the specific events, the parts this call changed (position, rotation, scale).

They come from the setters and from prop edits, in play and in the editor. Writing entity.position directly, or physics moving the body, sends nothing.

comp-enable turns the entity and everything under it on or off. It is required on every element and cannot itself be disabled. It is the one on/off switch a scene saves.

Prop Type Default Description
enabled boolean true Off hides and silences the entity’s subtree and stops its behaviour: no ticking, no physics, no audio, video or animation, and its scripts pause.

From a script, use the entity shortcuts: entity.setEnabled(on) to switch, and entity.isEnabled() to ask whether the entity is effectively on (its own flag and every ancestor’s).

Event EventType Data
Enable::change EventType.Enable.Change { enabled }: the entity was enabled or disabled.

comp-layer puts the entity, and what it builds or loads, on one layer. Layers group entities so they can be switched off, locked or made unclickable together. It is required on every element.

Prop Type Default Description
layer integer 0 A user layer, 0 to 20. Values 21 to 31 are reserved for the runtime and rejected.

From a script, call entity.setLayer(n); read the current layer with entity.getComponent(LayerComponent).layer.

Event EventType Data
Layer::change EventType.Layer.Change { layer }: the entity moved to another layer.

Layers explains what a layer controls.

comp-lock is an editor flag: a locked entity cannot be picked in the editor’s viewport or transformed there. It is not a run-time freeze: scripts and physics still move a locked entity. It is required on every element.

Prop Type Default Description
locked boolean false Blocks selection in the viewport and transforming in the editor.

From a script, call entity.setLocked(on); read it with entity.getComponent(LockComponent).locked.

Event EventType Data
Lock::change EventType.Lock.Change { locked }: the entity was locked or unlocked.

comp-billboard keeps the entity turned toward the camera, for sprites, labels and name tags. The entity’s local +Z axis is aimed at the camera.

Prop Type Default Description
lockY boolean true Turn around the world Y axis only, so the entity stays upright. false faces the camera fully, tilting up and down too.

On most entities, Billboard turns the entity itself, in play only, so the saved rotation never changes. On a UI panel it turns the panel’s drawn content instead, and also works in the editor. It sends no events.

comp-group is found only on Group entities (ent-group). It has no props. It recenters the group on demand: recenter() moves the group’s origin to the centre of its children’s bounding box, and every child stays where it is in the world. Nothing else triggers it: adding, removing or moving children leaves the origin where it is.

  • A child counts by what it draws, everything under it included. A child that draws nothing, such as a light or an empty group, counts as a point at its position.
  • Only positions change: the group’s rotation and scale, and its children’s, stay.
  • Locked Transform axes do not stop it.
  • It returns the entities it moved, the group first, or an empty list when there is no child entity or the group is already centred.

It sends no events.

comp-shadow decides whether the entity’s meshes cast and receive shadows. Without it they do neither. Entity types choose their own starting values: a new primitive mesh casts but does not receive.

Prop Type Default Description
cast boolean true The meshes cast shadows.
receive boolean true The meshes receive shadows.

It sends Shadow::change (EventType.Shadow.Change) with { changed }, only the settings that changed. Lights, shadow maps and shadow quality are covered in Lighting.

comp-dont-unload has no props. It keeps the entity, and everything under it, when its scene is switched away in play: the entity moves to the new scene, still running. A script can do the same with #pragma dont_unload(). See Scene switching.

1. Move an object and hear its Transform events

Section titled “1. Move an object and hear its Transform events”

This script gives a crate a Signal Emitter for its position changes, then moves it with a setter. Each move arrives back as an event.

TransformEcho.jx
#pragma lifecycle(startup)
function startup() {
const crate = findEntity('Crate');
if (!crate) return;
crate.addComponent(new SignalEmitterComponent({
signal: 'crate/moved',
eventFilter: ['Transform::position-change'],
}));
on('crate/moved', (event) => {
const p = event.data.position;
log('Crate now at', p.x.toFixed(2), p.y.toFixed(2), p.z.toFixed(2));
});
crate.setPosition(1, 0.5, -2); // sends an event
crate.position.x += 1; // a direct write: sends nothing
}

How it works:

  • The Signal Emitter forwards only Transform::position-change, thanks to its eventFilter.
  • setPosition sends the event, so the log line appears.
  • The direct write to crate.position.x moves the crate but sends nothing.

This script gives every entity whose name ends in Tag a Billboard, so labels stay readable from anywhere.

FaceCamera.jx
#pragma lifecycle(startup)
function startup() {
let count = 0;
scene.entities.forEach((entity) => {
if (!entity.name.endsWith('Tag')) return;
if (entity.getComponent(BillboardComponent)) return;
entity.addComponent(new BillboardComponent({ lockY: true }));
count += 1;
});
log('Billboards added:', count);
}

How it works:

  • scene.entities holds every entity of the scene, by id.
  • The check with getComponent skips entities that already have a Billboard.
  • lockY: true keeps the tags upright; they only turn around the vertical axis.

A script that spawns pieces under a group can recenter the group afterwards, so the group turns around the middle of its contents.

Recenter.jx
#pragma lifecycle(startup, update)
let pile = null;
function startup() {
pile = findEntity('Pile');
const group = pile && pile.getComponent(GroupComponent);
if (!group) {
log('Pile is not a Group entity');
return;
}
for (let i = 0; i < 4; i++) {
spawn('Brick', { parent: pile, position: { x: 2 + i * 0.6, y: 0.25, z: 1 }, enabled: true });
}
const moved = group.recenter();
log('Recentered; entities moved:', moved.length);
}
function update(dt) {
if (pile) pile.rotation.y += dt * 0.5;
}

How it works:

  • spawn copies an entity named Brick under the group; enabled: true switches on copies of a disabled template.
  • recenter() moves the group’s origin to the middle of the bricks without moving them in the world.
  • Turning pile.rotation.y then spins the bricks around their own centre, not around the old origin.

A realistic script for a room: the E key switches a lamp on and off, and on phones and tablets shadows are turned off to save work.

RoomControls.jx
#pragma lifecycle(startup, update)
let lamp = null;
function reduceShadows() {
let changed = 0;
scene.entities.forEach((entity) => {
const shadow = entity.getComponent(ShadowComponent);
if (!shadow) return;
shadow.setProps({ cast: false, receive: false });
changed += 1;
});
log('Shadows off on', changed, 'entities');
}
function startup() {
lamp = findEntity('Desk Lamp');
if (!lamp) log('No entity named Desk Lamp');
if (Device.isMobile()) reduceShadows();
}
function update() {
if (lamp && Input.keyboard.isKeyReleased(Key.E)) {
lamp.setEnabled(!lamp.isEnabled());
log('Lamp is', lamp.isEnabled() ? 'on' : 'off');
}
}

How it works:

  • reduceShadows walks every entity once and switches its Shadow off, only on mobile devices (Device.isMobile()).
  • isKeyReleased is true for one frame per key press, so each press toggles exactly once.
  • setEnabled changes the lamp’s Enable component; isEnabled() reads the result back.
  • The script keeps working while the lamp is off because it sits on another entity. A script under the lamp would pause with it.

Writing position and expecting physics to follow

Section titled “Writing position and expecting physics to follow”

A direct write moves what is drawn, but the colliders stay where they were and no event is sent.

Wrong
crate.position.set(0, 3, 0); // the physics body is left behind
Right
crate.setPosition(0, 3, 0);

Expecting Lock or axis locks to stop a script

Section titled “Expecting Lock or axis locks to stop a script”

Lock and the Transform lock… props protect an entity from the editor’s tools only. In play, scripts, physics and animation move it freely. To keep an entity still in play, simply do not move it, or switch off what moves it.

Transform, Enable, Layer and Lock are always enabled; other required components can be disabled. To switch the entity off, use its own switch.

Wrong
door.getComponent(EnableComponent).setEnabled(false);
Right
door.setEnabled(false);

Layers 21 to 31 belong to the runtime; a Layer component rejects them with an error.

Wrong
marker.setLayer(25);
Right
marker.setLayer(5);