Skip to content

Rect Area Light

Updated

A soft glowing rectangle, like a window or a panel light.

Type
ent-rect-area-light
Script class
RectAreaLightEntity
Family
Lights

A Rect Area Light is a soft, glowing rectangle of light: a window, a ceiling panel, a TV screen, a neon sign. Unlike a bulb, its light comes from a whole surface, so it lights objects softly and makes long, smooth highlights on shiny materials.

Its settings live in its required Rect Area Light component (comp-rect-area-light). The rectangle lies in the entity’s local XY plane and emits along its local -Z axis, so you place and aim it by moving and rotating the entity. In the editor it shows an icon in its colour and, while selected, its aim; play builds none of these.

Pick it for broad, soft sources. It casts no shadows and lights only Standard and Physical materials; other materials ignore it. When you need shadows, use a Spot Light; for a small source that shines all around, a Point Light.

The props:

  • width and height are the size of the rectangle, in metres, along the entity’s local X and Y.
  • intensity is the brightness, in candela per square metre, from 0 to 100000. A new entity starts at 5.
  • color tints the light.
  1. Add a Rect Area Light entity to the scene (see Scenes and hierarchy) and place it on the glowing surface, for example just inside a window.
  2. Rotate it so its -Z axis points into the room.
  3. Set width and height to the size of the surface, then intensity and color.
  4. Check that the objects it should light use a Standard or Physical material.

Goal: size a window light to the window opening and give it a cool daylight tint.

WindowLight.jx
#pragma lifecycle(startup)
function startup() {
const windowLight = findEntity('Window Light').getComponent(RectAreaLightComponent);
windowLight.setProps({ width: 1.6, height: 1.2, color: '#dce8ff', intensity: 8 });
}
  • getComponent(RectAreaLightComponent) returns the light’s component; setProps changes all four props at once.
  • width and height are in metres, along the entity’s local X and Y, so they follow the rectangle however the entity is turned.

Goal: make the light of a TV change colour and brightness every few frames, like a film playing in a dark room.

The Behavior entity is a child of the Rect Area Light placed in front of the screen.

TvGlow.jx
#pragma lifecycle(startup, update)
const COLORS = ['#9fb8ff', '#ffd0a0', '#c0ffd0', '#ffffff'];
let tv;
let wait = 0;
function startup() {
tv = self.parent.getComponent(RectAreaLightComponent);
}
function update(dt) {
wait -= dt;
if (wait > 0) return;
wait = Random.range(0.1, 0.4);
tv.setProps({
color: Random.pick(COLORS),
intensity: Random.range(3, 7),
});
}
  • self.parent is the light above the Behavior in the Hierarchy.
  • The light changes at random intervals between 0.1 and 0.4 seconds, never every frame.
  • Random.pick(array) returns one item of the array; Random.range(min, max) a random number between the two.

Goal: make a neon sign breathe slowly between dim and bright, forever.

NeonPulse.jx
#pragma lifecycle(startup)
function startup() {
const neon = findEntity('Neon Sign').getComponent(RectAreaLightComponent);
neon.setProps({ color: '#ff2d95', width: 2, height: 0.4 });
Tween.value(2, 10, (value) => neon.setProps({ intensity: value }), {
duration: 1.5,
ease: Ease.InOutSine,
repeat: Infinity,
yoyo: true,
});
}
  • A long, thin rectangle (2 × 0.4 m) matches the shape of the sign.
  • Tween.value animates a plain number from 2 to 10 and hands each value to setProps. repeat: Infinity with yoyo: true plays it back and forth forever.
  • Ease.InOutSine slows the pulse at each end, which reads as a gentle breath.
  • The light emits along local -Z only. If nothing is lit, turn the entity around.
  • Change it with intensity rather than by disabling it: enabling or disabling a light recompiles every lit material.

What a new Rect Area Light 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.
Rect Area Light comp-rect-area-light Required One A soft glowing rectangle, like a window or a panel light.

You can also add 6 optional components, such as Animation Graph, Animation Timeline, Motion Path Controller, 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
color "#ffffff"
intensity 5 0 ≤ x ≤ 100000
width 1 0 ≤ x ≤ 1000
height 1 0 ≤ x ≤ 1000

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

  • RectAreaLight::change

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 Rect Area Light.

RectAreaLightEntity.jx
#pragma lifecycle(startup)
function startup() {
// Find the entity by the name it has in the Hierarchy.
const entity = findEntity('My Rect Area Light');
if (!(entity instanceof RectAreaLightEntity)) return;
// Its Rect Area Light component holds the settings listed under Props.
const component = entity.getComponent(RectAreaLightComponent);
log('intensity is', component.props.intensity);
component.setProps({ intensity: 7.5 });
}