Skip to content

Decal

Updated

Stamps an image onto every surface inside its box, like a sticker.

Type
ent-decal
Script class
DecalEntity
Family
Effects

A Decal entity stamps an image onto the surfaces inside its box, like a sticker or a spray of paint: a logo on a wall, a scorch mark on the floor, a puddle on uneven ground. The meshes it stamps are never changed. The decal adds overlays of its own that follow their shape, so one image wraps over steps, rocks and curved walls without editing any model.

The box is the entity’s transform: move, turn and scale the entity to place it, and the scale is the box’s size in metres. The decal projects along its local -Z axis and stamps only faces turned toward it. In the editor every decal acts as a live projector, so it always shows what it will paint when play starts.

Use a Decal to put an image on existing surfaces. To show an image as its own flat object, use an image entity from the Media family instead; to clip what is drawn rather than add to it, use a Mask.

The props that matter most, on its required Decal component (comp-decal):

  • src is the image: a URL or a project asset reference.
  • type decides what the decal does in play. fixed paints once, on its first frame, and the overlay then belongs to the mesh it painted. dynamic is a live projector that recuts meshes moving through its box.
  • targets limits the stamp to the listed objects and everything under them. Empty means any object the box touches.
  • color tints the image (white keeps it as it is) and opacity fades it, from 0 to 1.
  1. Add a Decal entity to the scene (see Scenes and hierarchy).
  2. Place the box against the surface and turn it so its local -Z points into the surface. Scale it to the size the image should cover.
  3. Set src to the image, and keep type at fixed for marks that never move.
  4. Add the objects it may paint to targets, so it never stamps the plants or props in front of the wall.
  5. For marks that scripts copy at run time, keep one disabled template decal in the scene and spawn enabled copies of it.

Goal: a mural painted on a wall appears gradually when another script emits mural/reveal.

RevealMural.jx
#pragma lifecycle(startup)
function startup() {
const decal = findEntity('Mural').getComponent(DecalComponent);
decal.setProps({ opacity: 0, targets: [findEntity('Alley Wall')] });
on('mural/reveal', () => {
Tween.value(0, 1, (value) => decal.setProps({ opacity: value }), {
duration: 2,
ease: Ease.InOutSine,
});
});
}
  • getComponent(DecalComponent) returns the decal on the Mural entity.
  • In a script, targets accepts entities, entity ids or names. Limiting the decal to the wall also saves work, since it no longer tests other objects.
  • Tween.value animates a plain number for two seconds and passes each value to setProps. Changing opacity keeps the loaded image, so the mural never blinks.

Goal: a sign shows a different poster every five seconds.

The Behavior entity is placed under the Decal entity.

PosterRotation.jx
#pragma lifecycle(startup)
const POSTERS = [
'https://example.com/posters/concert.png',
'https://example.com/posters/market.png',
'https://example.com/posters/cinema.png',
];
let index = 0;
function startup() {
const decal = self.parent.getComponent(DecalComponent);
decal.setProps({ src: POSTERS[index] });
function next() {
index = (index + 1) % POSTERS.length;
decal.setProps({ src: POSTERS[index] });
delay(next, 5000);
}
delay(next, 5000);
}
  • self.parent is the Decal entity above the Behavior.
  • Changing src loads the new image and restamps it.
  • delay(fn, ms) runs fn after that many milliseconds of game time; next schedules itself again, which makes a loop. Pending delays are cancelled when the script stops.

Leave scorch marks where the player clicks

Section titled “Leave scorch marks where the player clicks”

Goal: each click on the floor leaves a mark, and only the 20 newest marks are kept.

A disabled template decal named Scorch Template projects straight down (rotation x of -90 degrees, box 1 × 1 × 0.5 m) and sits at the top of the scene.

ScorchMarks.jx
#pragma lifecycle(startup, update)
const MAX_MARKS = 20;
const marks = [];
let floor;
function startup() {
floor = findEntity('Floor');
}
function update() {
if (!Input.mouse.isButtonReleased(MouseButton.Left)) return;
const hit = GraphicsRaycaster.fromScreen(Input.mouse.position()).hit(floor);
if (!hit) return;
const mark = spawn('Scorch Template', {
position: { x: hit.point.x, y: hit.point.y + 0.1, z: hit.point.z },
rotation: { x: -M_HALF_PI, y: 0, z: Random.range(0, M_TAU) },
enabled: true,
});
mark.getComponent(DecalComponent).setProps({ type: 'fixed', targets: [floor] });
marks.push(mark);
if (marks.length > MAX_MARKS) destroy(marks.shift());
}
  • Input.mouse.isButtonReleased(MouseButton.Left) is true once per click.
  • GraphicsRaycaster.fromScreen(...) casts a ray from the camera through the pointer; .hit(floor) returns the nearest hit on the floor, or null.
  • spawn copies the template just above the hit point, keeps it pointing down, turns it randomly around its projection axis and enables it so it paints.
  • type: 'fixed' paints once and then costs almost nothing, which suits marks that never move.
  • destroy(marks.shift()) removes the oldest mark once there are more than MAX_MARKS.
  • If nothing shows, the box probably points the wrong way: the decal projects along local -Z and skips faces turned away from it.
  • A fixed decal does not paint objects that move into its box later. Use dynamic for those.
  • Fire, water and UI panels are never stamped, and overlays cast no shadow.
  • Keep templates disabled: an enabled template paints too.

What a new Decal 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.
Transform comp-transform Required One Position, rotation and scale of the entity, with optional editor-only per-axis locks.
Decal comp-decal Required One Stamps an image onto every surface inside its box, like a sticker.

You can also add 3 optional components, such as Networkable, Networkable Trait, Signal Emitter.

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
type "fixed"
color "#ffffff"
opacity 1 0 ≤ x ≤ 1
targets []

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

It reports the events every entity has: 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 Decal.

DecalEntity.jx
#pragma lifecycle(startup)
function startup() {
// Find the entity by the name it has in the Hierarchy.
const entity = findEntity('My Decal');
if (!(entity instanceof DecalEntity)) return;
// Its Decal component holds the settings listed under Props.
const component = entity.getComponent(DecalComponent);
log('opacity is', component.props.opacity);
component.setProps({ opacity: 1 });
}