Skip to content

Ambient Light

Updated

Even light from everywhere, with no direction or shadows.

Type
ent-ambient-light
Script class
AmbientLightEntity
Family
Lights

An Ambient Light adds even light from everywhere at once. It has no position that matters, no direction and no shadows: it brightens every lit material by the same amount, so nothing in the scene is ever fully black.

Its settings live in its required Ambient Light component (comp-ambient-light). The editor and play light the scene the same way; in the editor the light also shows an icon in its colour, which play never builds.

Because it lights every surface equally, an ambient light flattens shapes. Keep it low and use it as a last touch of fill. For outdoor fill with a sense of up and down, prefer a Hemisphere Light; for light that comes from somewhere, use a Directional, Point or Spot light. An Environment on the scene root can provide richer ambient light from an HDRI.

The props:

  • intensity is the brightness, from 0 to 100. Set it to 0 to switch the light off cheaply.
  • color tints the light. A slightly blue fill reads as shade; a warm one as candle-lit interiors.
  1. Add an Ambient Light entity to the scene (see Scenes and hierarchy). Where you place it makes no difference.
  2. Lower intensity until shadowed areas are dark but still readable, often between 0.1 and 0.5 when other lights do the main work.
  3. Set color to match the mood of the scene.
  4. To react to changes from scripts, add a Signal Emitter to the entity.

Goal: give the scene a soft blue-grey fill that keeps the shadows from going black.

AmbientSetup.jx
#pragma lifecycle(startup)
function startup() {
const ambient = findEntity('Ambient Light').getComponent(AmbientLightComponent);
ambient.setProps({ color: '#b8c4d8', intensity: 0.25 });
log('Ambient intensity is', ambient.props.intensity);
}
  • findEntity('Ambient Light') finds the entity by its name in the Hierarchy. Look entities up once, in startup.
  • getComponent(AmbientLightComponent) returns the light’s component; setProps changes only the keys passed to it.
  • ambient.props.intensity reads the current value back.

Goal: when another script emits power/off, the ambient fill fades out over a second, and power/on brings it back.

Blackout.jx
#pragma lifecycle(startup)
const NORMAL = 0.4;
let ambient;
let fade = null;
function fadeTo(target, seconds) {
if (fade) fade.stop();
fade = Tween.value(ambient.props.intensity, target, (value) => {
ambient.setProps({ intensity: value });
}, { duration: seconds, ease: Ease.InOutSine });
}
function startup() {
ambient = findEntity('Ambient Light').getComponent(AmbientLightComponent);
on('power/off', () => fadeTo(0, 1));
on('power/on', () => fadeTo(NORMAL, 2));
}
  • Tween.value(start, end, onValue, options) animates a plain number and passes each value to onValue, where the script calls setProps.
  • A running fade is stopped before a new one starts, so a quick off-on never leaves two tweens fighting.
  • The light is never disabled: setting intensity to 0 turns it off without making lit materials recompile.

Goal: log every brightness change of the ambient light, whoever made it.

The Ambient Light entity has a Signal Emitter whose signal is ambient.

AmbientWatcher.jx
#pragma lifecycle(startup)
function startup() {
on('ambient', (event) => {
if (event.eventType !== EventType.AmbientLight.Change) return;
const { changed } = event.data;
if ('intensity' in changed) log('Ambient is now', changed.intensity);
if ('color' in changed) log('Ambient colour is now', changed.color);
});
}
  • The Signal Emitter forwards the entity’s events on the ambient signal. The script keeps only EventType.AmbientLight.Change.
  • event.data.changed holds only the props that actually changed, with their new values.
  • A setProps call that changes nothing sends no event.
  • Too much ambient light makes a scene look flat and washed out. If everything looks the same brightness, lower it and let directional lights shape the objects.
  • Tween.to(ambient.props, …) changes the numbers without applying them. Use Tween.value with setProps, as above.

What a new Ambient 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.
Ambient Light comp-ambient-light Required One Even light from everywhere, with no direction or shadows.

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 1 0 ≤ x ≤ 100

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

  • AmbientLight::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 Ambient Light.

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