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
Overview
Section titled “Overview”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:
widthandheightare the size of the rectangle, in metres, along the entity’s local X and Y.intensityis the brightness, in candela per square metre, from0to100000. A new entity starts at5.colortints the light.
Set it up
Section titled “Set it up”- 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.
- Rotate it so its -Z axis points into the room.
- Set
widthandheightto the size of the surface, thenintensityandcolor. - Check that the objects it should light use a Standard or Physical material.
Examples
Section titled “Examples”Fit the light to a window
Section titled “Fit the light to a window”Goal: size a window light to the window opening and give it a cool daylight tint.
#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;setPropschanges all four props at once.widthandheightare in metres, along the entity’s local X and Y, so they follow the rectangle however the entity is turned.
A flickering TV screen
Section titled “A flickering TV screen”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.
#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.parentis 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.
A neon sign that pulses
Section titled “A neon sign that pulses”Goal: make a neon sign breathe slowly between dim and bright, forever.
#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.4m) matches the shape of the sign. Tween.valueanimates a plain number from 2 to 10 and hands each value tosetProps.repeat: Infinitywithyoyo: trueplays it back and forth forever.Ease.InOutSineslows 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
intensityrather than by disabling it: enabling or disabling a light recompiles every lit material.
Components
Section titled “Components”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- |
Required | One | Position, rotation and scale of the entity, with optional editor-only per-axis locks. |
| Rect Area Light | comp- |
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 |
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.
RectAreaLight::change
Like every entity, it also reports: 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.
A photo-studio softbox: a Rect Area Light with the runtime Lobby demo's warm settings throws soft, even light from a whole rectangle, and the script cycles its colour and size.
Watch the soft light on the floor and the shapes change as the panel changes colour and size. 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 Rect Area Light.
#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 });}