Decal
Updated
Stamps an image onto every surface inside its box, like a sticker.
- Type
ent-decal- Script class
DecalEntity- Family
- Effects
Overview
Section titled “Overview”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):
srcis the image: a URL or a project asset reference.typedecides what the decal does in play.fixedpaints once, on its first frame, and the overlay then belongs to the mesh it painted.dynamicis a live projector that recuts meshes moving through its box.targetslimits the stamp to the listed objects and everything under them. Empty means any object the box touches.colortints the image (white keeps it as it is) andopacityfades it, from 0 to 1.
Set it up
Section titled “Set it up”- Add a Decal entity to the scene (see Scenes and hierarchy).
- 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.
- Set
srcto the image, and keeptypeatfixedfor marks that never move. - Add the objects it may paint to
targets, so it never stamps the plants or props in front of the wall. - For marks that scripts copy at run time, keep one disabled template decal in the scene and
spawnenabled copies of it.
Examples
Section titled “Examples”Fade a mural in on a signal
Section titled “Fade a mural in on a signal”Goal: a mural painted on a wall appears gradually when another script emits mural/reveal.
#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 theMuralentity.- In a script,
targetsaccepts entities, entity ids or names. Limiting the decal to the wall also saves work, since it no longer tests other objects. Tween.valueanimates a plain number for two seconds and passes each value tosetProps. Changingopacitykeeps the loaded image, so the mural never blinks.
Rotate posters on a sign
Section titled “Rotate posters on a sign”Goal: a sign shows a different poster every five seconds.
The Behavior entity is placed under the Decal entity.
#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.parentis the Decal entity above the Behavior.- Changing
srcloads the new image and restamps it. delay(fn, ms)runsfnafter that many milliseconds of game time;nextschedules 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.
#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)istrueonce per click.GraphicsRaycaster.fromScreen(...)casts a ray from the camera through the pointer;.hit(floor)returns the nearest hit on the floor, ornull.spawncopies 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 thanMAX_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
dynamicfor those. - Fire, water and UI panels are never stamped, and overlays cast no shadow.
- Keep templates disabled: an enabled template paints too.
Components
Section titled “Components”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- |
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 |
[] |
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.
It reports the events every entity has: 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.
Each click on the floor copies a disabled template Decal with spawn, turned to project straight down, at a random angle and opacity; past twenty marks the oldest is destroyed.
Click the floor to leave marks. 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 Decal.
#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 });}