Skip to content

Point Light

Updated

A light bulb that shines in every direction.

Type
ent-point-light
Script class
PointLightEntity
Family
Lights

A Point Light is a light bulb: it shines in every direction from the entity’s position. Use it for lamps, torches, candles, glowing crystals and the glow around a fire.

A new Point Light entity starts with two components: the required Point Light (comp-point-light) that holds its colour and brightness, and an enabled Light Shadow (comp-light-shadow) that makes it cast shadows. Disable or remove the Light Shadow for a light that should cast nothing. In the editor the light shows an icon in its colour and, while selected, its range; play builds none of these.

Pick a Point Light for light that spreads from a spot. For a cone of light, such as a desk lamp or a stage light, use a Spot Light; for a soft glowing panel or window, a Rect Area Light; for sunlight, a Directional Light.

The props that matter most:

  • intensity is the brightness, in candela, from 0 to 100000.
  • color tints the light.
  • distance is the maximum range in metres, from 0 to 1000. 0 means no limit. Past it the light adds nothing and its shadow reaches no further.
  • decay is how quickly the light fades with distance, from 0 to 10. 2 is physically correct.
  • On the Light Shadow, mapSize sets the shadow resolution and radius the softness of its edges.
  1. Add a Point Light entity to the scene (see Scenes and hierarchy) and move it where the bulb is.
  2. Set color and intensity, then give it a distance that covers only the area it should light.
  3. Decide about shadows: on phones and headsets, disable its Light Shadow and ground objects with a Contact Shadow instead.
  4. To react to changes, or to make a switch, add a Signal Emitter to the light, or a Selectable and a Signal Emitter to the switch object.

Goal: make a torch’s light waver like a flame, about fourteen times a second.

The Behavior entity is a child of the torch’s Point Light.

TorchFlicker.jx
#pragma lifecycle(startup, update)
const BASE = 1.4;
const SPREAD = 0.35;
const STEP = 0.07;
let torch;
let wait = 0;
let current = BASE;
function startup() {
torch = self.parent.getComponent(PointLightComponent);
torch.setProps({ color: '#ffa040', distance: 6 });
}
function update(dt) {
wait -= dt;
if (wait > 0) return;
wait = STEP;
const target = BASE + Random.range(-SPREAD, SPREAD);
current += (target - current) * 0.5;
torch.setProps({ intensity: current });
}
  • self is the Behavior’s own entity, and parent is the light above it in the Hierarchy.
  • update(dt) runs every frame, but the light changes only every STEP seconds, so setProps runs a few times a second rather than at the full frame rate.
  • Random.range(min, max) returns a random number between the two. Moving halfway toward each new target smooths the flicker.
  • distance: 6 keeps the torch from lighting things far away, which also keeps its shadow small.

Goal: clicking a wall switch fades the room’s light on or off in a quarter of a second.

The switch entity has a Selectable and a Signal Emitter whose signal is switch/clicked. The room’s light is named Room Light.

LightSwitch.jx
#pragma lifecycle(startup)
const ON = 2.5;
let light;
let isOn = true;
function startup() {
light = findEntity('Room Light').getComponent(PointLightComponent);
on('switch/clicked', (event) => {
if (event.eventType !== EventType.Selectable.Select) return;
findEntity(event.entityId)?.getComponent(SelectableComponent)?.setSelected(false); // so the next click selects it again
isOn = !isOn;
Tween.value(light.props.intensity, isOn ? ON : 0, (value) => {
light.setProps({ intensity: value });
}, { duration: 0.25 });
});
}
  • The Signal Emitter forwards every event of the switch, so the script keeps only EventType.Selectable.Select, the click.
  • Tween.value animates a plain number from the current intensity to the target and hands each value to setProps.
  • The light stays enabled. Switching with intensity avoids recompiling every lit material.

Goal: keep the lamp’s real-time shadow on desktop, but turn it off once at startup on mobile devices and headsets.

LampShadowQuality.jx
#pragma lifecycle(startup)
function startup() {
const lamp = findEntity('Desk Lamp');
const shadow = lamp.getComponent(LightShadowComponent);
if (!shadow) return;
if (Device.isMobile() || Device.isHeadset()) {
shadow.setEnabled(false);
} else {
shadow.setProps({ mapSize: 512, radius: 2 });
}
}
  • getComponent(LightShadowComponent) returns undefined when the Light Shadow was removed, which the return handles.
  • Device.isMobile() and Device.isHeadset() tell the script what it runs on.
  • setEnabled(false) switches the shadow off. Turning a shadow on or off recompiles lit materials, so the script does it once, at startup.
  • On desktop, a larger mapSize sharpens the shadow and a larger radius softens its edges.
  • Give small lights a distance: their light stays where it belongs and their shadow reaches no further.
  • Do not tween light.props directly; it changes the numbers without applying them. Use Tween.value with setProps.
  • Find lights once in startup and keep the component, rather than looking them up by name in update.

What a new Point 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.
Point Light comp-point-light Required One A light bulb that shines in every direction.
Light Shadow comp-light-shadow Starts with One Adds real-time and baked shadows to the light beside it.

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 ≤ 100000
distance 0 0 ≤ x ≤ 1000
decay 2 0 ≤ x ≤ 10
Prop Default Range
mapSize 256 1 ≤ x ≤ 2048
bias 0
radius 1 0 ≤ x ≤ 16
range 0 0 ≤ x ≤ 1000

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

  • PointLight::change
  • LightShadow::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 Point Light.

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