Skip to content

Decals

Updated

A decal 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, a bullet hole. The meshes it stamps are never changed. The decal adds overlays of its own that follow their shape, so one image can wrap over steps, rocks and curved walls without you editing any model.

Scripts move decals, change their image and colour, choose which objects they may stamp, and copy them to leave marks where things happen.

  • Entities and transforms. A decal’s box is its entity’s position, rotation and scale. See Working with entities.
  • Spawning. Leaving many marks means copying a template decal with spawn. See Scripting.
  • Raycasts. To find where the pointer touches a surface, use GraphicsRaycaster. See Input and interaction.
ComponentTypeWhat it does
Decalcomp-decalStamps an image onto every surface inside its box, like a sticker.

A Decal entity (ent-decal) is one projector, and its required DecalComponent holds the image and the settings.

  • The box is the transform. Move, turn and scale the entity to place the box; the scale is the box’s size in metres.
  • It projects along its local -Z. It stamps the objects its box intersects, on the faces turned toward it.
  • Clean edges. A face turned away, or seen almost edge-on (past 80 degrees), stays bare instead of showing the image mirrored or streaked.
Prop Type Default Description
src string none The image: a URL or an ASSET-<uuid> reference.
type 'fixed' | 'dynamic' 'fixed' How it behaves in play (below).
color string '#ffffff' Tint multiplied over the image. White keeps the image as it is.
opacity number 1 Overall opacity, 0 to 1.
targets string[] [] The objects it may stamp, each with everything under it. Empty: any object its box touches.

Targets. In a script, give targets as entities, entity ids or names: setProps({ targets: [findEntity('Statue'), 'Wall'] }). They are saved as an entity’s id or a plain object’s name. Setting targets also saves work: the decal does not test every other object.

Editing keeps the image. A setProps call keeps the loaded image unless src changes, so a decal never blinks out while you change its colour or opacity.

The type prop decides what the decal does after play starts. It can change at any time, in play too; the decal recuts its overlays on the next frame.

  • fixed is paint. On its first frame in play it stamps what its box holds. Each overlay then becomes part of the mesh it paints: it moves, animates, hides and is removed with that object. Moving or editing the decal paints again once it holds still for a frame. An object that moves into the box later is not painted.
  • dynamic is a projector. A mesh that moves relative to it is cut again on the frame it moves, and loses its stamp once it leaves the box. It also scans its box every 30 frames for objects that load or appear. To make a mark travel with an object, make the decal a child of that object: moving together, nothing is cut again.

In the editor every decal acts as a live projector, so it always shows what a fixed decal will paint when play starts.

  • Plain meshes are cut to the box.
  • Skinned meshes (characters) are cut from their pose at that moment, and the overlay rides on the character’s skeleton and blend shapes: it follows every animation at no cost to scripts.
  • Cached meshes are stamped through their hidden stand-in.
  • Skipped: hidden meshes, editor helpers (other decals included), UI panels, fire and water.

A stamp goes away when its mesh is removed or hidden. Overlays cast no shadow and are left out of outlines, colliders and navigation meshes.

Member What it does
setProps(patch) Change src, type, color, opacity or targets. Targets accept entities, ids or names.
setEnabled(on) Show or hide the decal.
props The current props.

The decal entity itself is moved like any entity: position, rotation, scale, or setPosition, setRotation, setScale.

A Decal entity named Graffiti is placed against a wall, its targets set to the wall so it never paints the plants in front. This script fades it in when a signal arrives.

RevealGraffiti.jx
#pragma lifecycle(startup)
function startup() {
const decal = findEntity('Graffiti').getComponent(DecalComponent);
decal.setProps({ opacity: 0, targets: [findEntity('Alley Wall')] });
on('mural/reveal', async () => {
await Tween.value(0, 1, (value) => decal.setProps({ opacity: value }), { duration: 2, ease: Ease.InOutSine });
log('Mural revealed');
});
}
  • getComponent(DecalComponent) gets the decal on the Graffiti entity.
  • targets: [findEntity('Alley Wall')] limits the stamp to the wall and everything under it. The decal skips every other object, which is also cheaper.
  • Tween.value(0, 1, …) animates a plain number over two seconds and hands each value to the callback, which writes it with setProps. Opacity changes never reload the image.
  • await waits for the tween to finish before logging; it is allowed because the listener is an async function.

2. Leave scorch marks where the player clicks the floor

Section titled “2. Leave scorch marks where the player clicks the floor”

A realistic pattern: keep one template decal in the scene, disabled and turned to project straight down (rotation x of -90 degrees, box 1 × 1 × 0.5 m), and copy it with spawn wherever the player clicks. A cap keeps the number of marks bounded.

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], opacity: Random.range(0.6, 1) });
marks.push(mark);
if (marks.length > MAX_MARKS) destroy(marks.shift());
}
  • Input.mouse.isButtonReleased(MouseButton.Left) is true once per click.
  • GraphicsRaycaster.fromScreen(Input.mouse.position()) builds a ray from the camera through the pointer. .hit(floor) tests only the floor and returns the nearest hit or null; hit.point is where it touched, in world space.
  • spawn('Scorch Template', …) copies the disabled template. The copy is placed just above the hit, keeps the projector pointing down (-M_HALF_PI around x), gets a random turn around its own projection axis (z) so the marks do not all look the same, and is enabled so it paints.
  • The position is a local position under the scene root, which matches world space for a template placed at the top of the scene.
  • type: 'fixed' paints once and then costs almost nothing, which is the right choice for marks that never move.
  • The array works as a queue: once there are more than MAX_MARKS, the oldest mark is removed with destroy, which also frees its memory.

3. A spotlight logo that follows a moving platform

Section titled “3. A spotlight logo that follows a moving platform”

A dynamic decal recuts whenever what it stamps moves relative to it. This script projects a logo down onto a platform that slides back and forth under it, and changes its tint while the platform is moving fast.

ProjectedLogo.jx
#pragma lifecycle(startup, update)
let decal;
let platform;
let lastX = 0;
let fast = false;
function startup() {
decal = findEntity('Logo Projector').getComponent(DecalComponent);
decal.setProps({ type: 'dynamic', color: '#ffffff' });
platform = findEntity('Platform');
lastX = platform.position.x;
Tween.to(platform.position, { x: platform.position.x + 4 }, { duration: 3, ease: Ease.InOutSine, repeat: Infinity, yoyo: true });
}
function update(dt) {
if (dt === 0) return;
const speed = Math.abs(platform.position.x - lastX) / dt;
lastX = platform.position.x;
const isFast = speed > 1.5;
if (isFast === fast) return;
fast = isFast;
decal.setProps({ color: fast ? '#f97316' : '#ffffff' });
}
  • type: 'dynamic' makes the decal a live projector: the platform is cut again on the frames it moves, and the logo slides across its surface as it would under a real projector.
  • Tween.to(platform.position, …) moves the platform forever (repeat: Infinity), playing every other run backwards (yoyo: true).
  • update measures the platform’s speed from its position change and frame time. It skips frames where the game is paused (dt is 0) to avoid dividing by zero.
  • The colour changes only when the platform crosses the speed threshold, never every frame.

src can change at any time; the decal loads the new image and restamps. Here a sign cycles through three posters every five seconds.

PosterRotation.jx
#pragma lifecycle(startup, dispose)
const POSTERS = [
'/example-assets/lemon-decal.png',
'/example-assets/bang.png',
'/example-assets/alpha.png',
];
let index = 0;
let cancel = null;
function startup() {
const decal = self.parent.getComponent(DecalComponent);
function next() {
index = (index + 1) % POSTERS.length;
decal.setProps({ src: POSTERS[index] });
cancel = delay(next, 5000);
}
decal.setProps({ src: POSTERS[index] });
cancel = delay(next, 5000);
}
function dispose() {
if (cancel) cancel();
}
  • The Behavior sits on the Decal entity itself, so self.parent.getComponent(DecalComponent) finds it.
  • delay(next, 5000) runs next after five seconds of game time, and next schedules itself again, a loop without setInterval (scripts do not have it).
  • delay returns a cancel function. Pending delays are cancelled anyway when the script stops; calling it in dispose makes the intent explicit.
  • Changing src reloads the image. Keep the files small, since every change downloads a new one the first time.
  • A fixed decal checks one matrix a frame once it has painted: leave static marks fixed.
  • A dynamic decal checks the pose of what it stamps each frame and recuts only the meshes that changed. Keep moving dynamic decals few, and give them targets.
  • Targets spare the decal from testing every object its box might touch.
  • Pointing the box the wrong way. A decal projects along its local -Z and stamps only faces turned toward it. If nothing shows, turn the box around.
  • Expecting a fixed decal to paint objects that arrive later. A fixed decal paints once, on its first frame in play (and again when it is moved or edited). Use dynamic for objects that move into the box.
  • Leaving the template enabled. An enabled template paints too. Keep it disabled and spawn enabled copies.
  • Spawning marks without a limit. Each mark is an entity with its own overlays. Cap them and destroy the oldest, as in the scorch example.
  • Stamping fire, water or UI. These are drawn from shared batches and are skipped.