Point Light
Updated
A light bulb that shines in every direction.
- Type
ent-point-light- Script class
PointLightEntity- Family
- Lights
Overview
Section titled “Overview”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:
intensityis the brightness, in candela, from0to100000.colortints the light.distanceis the maximum range in metres, from0to1000.0means no limit. Past it the light adds nothing and its shadow reaches no further.decayis how quickly the light fades with distance, from0to10.2is physically correct.- On the Light Shadow,
mapSizesets the shadow resolution andradiusthe softness of its edges.
Set it up
Section titled “Set it up”- Add a Point Light entity to the scene (see Scenes and hierarchy) and move it where the bulb is.
- Set
colorandintensity, then give it adistancethat covers only the area it should light. - Decide about shadows: on phones and headsets, disable its Light Shadow and ground objects with a Contact Shadow instead.
- 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.
Examples
Section titled “Examples”A torch that flickers
Section titled “A torch that flickers”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.
#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 });}selfis the Behavior’s own entity, andparentis the light above it in the Hierarchy.update(dt)runs every frame, but the light changes only everySTEPseconds, sosetPropsruns 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: 6keeps the torch from lighting things far away, which also keeps its shadow small.
A light switch the player clicks
Section titled “A light switch the player clicks”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.
#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.valueanimates a plain number from the current intensity to the target and hands each value tosetProps.- The light stays enabled. Switching with
intensityavoids recompiling every lit material.
Cheaper shadows on phones and headsets
Section titled “Cheaper shadows on phones and headsets”Goal: keep the lamp’s real-time shadow on desktop, but turn it off once at startup on mobile devices and headsets.
#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)returnsundefinedwhen the Light Shadow was removed, which thereturnhandles.Device.isMobile()andDevice.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
mapSizesharpens the shadow and a largerradiussoftens its edges.
- Give small lights a
distance: their light stays where it belongs and their shadow reaches no further. - Do not tween
light.propsdirectly; it changes the numbers without applying them. UseTween.valuewithsetProps. - Find lights once in
startupand keep the component, rather than looking them up by name inupdate.
Components
Section titled “Components”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- |
Required | One | Position, rotation and scale of the entity, with optional editor-only per-axis locks. |
| Point Light | comp- |
Required | One | A light bulb that shines in every direction. |
| Light Shadow | comp- |
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({ … }).
Point Light
Section titled “Point Light”| Prop | Default | Range |
|---|---|---|
color |
"#ffffff" |
|
intensity |
1 |
0 ≤ x ≤ 100000 |
distance |
0 |
0 ≤ x ≤ 1000 |
decay |
2 |
0 ≤ x ≤ 10 |
Light Shadow
Section titled “Light Shadow”| Prop | Default | Range |
|---|---|---|
mapSize |
256 |
1 ≤ x ≤ 2048 |
bias |
0 |
|
radius |
1 |
0 ≤ x ≤ 16 |
range |
0 |
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.
PointLight::changeLightShadow::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 point light switched on and off every half second by a script that schedules itself with delay instead of setInterval.
Watch the lamp blink. 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 Point Light.
#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 });}