Content
Updated
Content elements show things inside a UI: text (UI Label), pictures (UI Image, UI Avatar), video (UI Video), a canvas your scripts draw on (UI Drawing) and a small 3D world (UI Render View with its UI Render Scene). They sit in a panel or layout like any control, or stand alone in the world as a root of their own. Most content is passive, but labels, images and avatars can be pressed, videos report playback, and a drawing reports every pointer movement.
Before you start
Section titled “Before you start”- Read the UI overview for roots, nesting and layout pixels.
- Content usually sits in a panel; see Panels and layout for spacing rules (
padding,margin,borderRadius). - Events reach scripts through a Signal Emitter, as for Controls.
- For world-space video, streams and Chroma Key, see Media and text.
UI Label
Section titled “UI Label”The UI Label component (comp-ui-label) draws text in a box you style with CSS-like props. Entity: UI Label (ent-ui-label), which also takes a Billboard, a Link, a Signal Emitter and an Enable on Signal.
| Prop | Type | Default | Description |
|---|---|---|---|
text |
string | 'Text' |
The text to draw. |
fontSize |
number | 16 from the theme |
Glyph size in px. |
font |
string | the theme’s | Font family, by name. See Placement and fonts. |
fontWeight |
'light', 'normal', 'medium', 'semi-bold', 'bold' |
'normal' |
Weight, when the family has it. |
color |
string | the theme’s foreground | Text colour. |
opacity |
number | opaque | Text alpha, 0 to 1. |
textAlign |
'left', 'center', 'right' |
'left' |
Alignment inside a box wider than the text. |
lineHeight |
number | 1.2 |
Line spacing as a multiple of the font size. |
letterSpacing |
number | 0 |
Extra space between glyphs, in px. |
width |
number or 'N%' |
fits the text | Fixed width in px or a percentage of the parent. |
maxWidth |
number or 'N%' |
none | The text wraps past this width. Without it, the label is one line. |
textOverflow |
'ellipsis' |
wraps | With width set, show one line ending in an ellipsis when the text is too wide. |
wordBreak |
'break-word', 'break-all', 'keep-all' |
normal | How words break inside a constrained width. |
overflowWrap |
boolean | none | Break a word too long for the width. |
minHeight, maxHeight |
number | none | Height limits in px. |
overflow |
'hidden' or 'scroll' |
none | What text past maxHeight does. |
padding, margin |
number or number[] | 1, none |
In px. |
background |
string | none | Box fill. |
borderRadius |
number or number[] | none | Corner radius in px. |
borderColor, borderWidth |
string, number or number[] | none, 2 |
Outline, drawn only when borderColor is set. |
- Pressable. With a Signal Emitter the label sends
UILabel::press{}(EventType.UILabel.Press) when pressed; with a Link it opens the link instead. Without either it takes no pointer, unlessoverflow: 'scroll'makes it scrollable. - Shared text. A label’s props can be a network trait (
NetworkTraitType.UILabel), so a scoreboard reads the same for everyone in a room. See Multiplayer. - A label floating over an object is covered in Placement and fonts.
UI Image
Section titled “UI Image”The UI Image component (comp-ui-image) shows a picture in its box. Entity: UI Image (ent-ui-image).
A UI Image that steps through three pictures with Previous and Next buttons; the caption waits for the image's ready event and reports load errors.
Press Next and Previous to step through the pictures; the caption updates once each one has loaded. Drag outside the panel to orbit the camera, scroll to zoom.
| Prop | Type | Default | Description |
|---|---|---|---|
src |
string | none | The picture: a URL or one of the project’s image assets. |
width, height |
number | automatic | Size in px. |
keep |
boolean | true |
Keep the picture’s proportions when only one size is set. |
objectFit |
'cover' or 'fill' |
'cover' |
cover crops to fill the box; fill stretches. |
padding, margin |
number or number[] | none | In px. |
borderRadius |
number or number[] | none | Corner radius in px. |
borderColor, borderWidth |
string, number or number[] | none | Outline, drawn only when borderWidth is set. |
With both sizes automatic, the image uses its natural size and scales down to fit the space it has. With one size set, keepAspectRatio derives the other.
| Event | EventType |
Data | Sent when |
|---|---|---|---|
UIImage::ready |
Event |
{ width, height } |
The image shows, and again after each rebuild. |
UIImage::error |
Event |
{ message } |
It cannot load. |
UIImage::press |
Event |
{} |
It is pressed, with a Signal Emitter and no Link. |
UI Avatar
Section titled “UI Avatar”The UI Avatar component (comp-ui-avatar) is a round profile picture with an optional status dot at its lower right. While the picture is missing or loading, it shows the initials you give it, or a user icon. Entity: UI Avatar (ent-ui-avatar).
A profile card built from a UI Avatar with initials and a status dot, a UI Spacer that pushes the level badge right, and UI Dividers between the stats. Pressing the avatar cycles the status.
Press the avatar to cycle Online, Away and Busy: the status dot and the label change together. Drag outside the panel to orbit the camera, scroll to zoom.
| Prop | Type | Default | Description |
|---|---|---|---|
src |
string | none | The picture, cropped to a circle. |
initials |
string | none | Fallback text while there is no picture. |
initials, initialsColor |
string | from the theme | Fill and text colour of the initials. |
initials |
number | the theme’s font size | Initials size in px. |
size |
number | 40 |
Diameter in px. |
borderColor, borderWidth |
string, number or number[] | none, 1 |
Ring, drawn only when borderColor is set. |
statusColor |
string | none | Status dot colour, such as green for online. Absent: no dot. |
padding, margin |
number or number[] | none | In px. |
Event: UIAvatar::press {} (EventType.UIAvatar.Press), with a Signal Emitter and no Link.
UI Video
Section titled “UI Video”The UI Video component (comp-ui-video) plays a video on a surface inside a panel. It plays the same sources as the world-space Video, including live streams through a Media Stream component, and a Chroma Key can make its green screen transparent. Entity: UI Video (ent-ui-video).
| Prop | Type | Default | Description |
|---|---|---|---|
src |
string | none | The video: a URL or one of the project’s video assets. |
width, height |
number | from the parent | Surface size in px. |
objectFit |
'cover' or 'fill' |
'cover' |
cover crops to fill; fill stretches. |
keep |
boolean | true |
Keep the video’s proportions. |
autoplay |
boolean | true |
Play once the surface is live, and again when the scene is entered. |
muted |
boolean | true |
Start muted, since browsers block autoplay with sound. |
volume |
number | 1 |
Gain, 0 to 1. |
repeat |
'once' or 'repeat' |
'repeat' |
Play to the end, or start again. |
playbackRate |
number | 1 |
Speed, 0.5 to 4. |
restart |
boolean | true |
Start from the beginning when the scene is entered again, instead of resuming. |
crossOrigin |
string | 'anonymous' |
Cross-origin mode. A video from another site must allow it to be drawn. |
padding, margin, borderRadius, borderColor, borderWidth |
none | The box, in px. borderRadius clips the video. |
| Method | What it does |
|---|---|
play() |
Start or resume. |
pause() |
Pause, keeping the position. |
stop() |
Stop and go back to the start. |
set, getVolume() |
Set or read the gain, 0 to 1. |
isPlaying() |
Whether it is playing. |
| Event | EventType |
Data | Sent when |
|---|---|---|---|
UIVideo::ready |
Event |
{ duration } |
The first frame loaded. duration in seconds, Infinity for a live stream. |
UIVideo::error |
Event |
{ message } |
The video or stream failed. |
UIVideo::play, ::pause, ::stop, ::end |
Event, .Pause, .Stop, .End |
{} |
Playback started, paused, was stopped, or reached its end without repeating. |
The video never plays while you edit. In play, the first ready and autoplay play events of a UI Image or UI Video arrive after Behaviors start: register your listeners in startup, before any await.
UI Drawing
Section titled “UI Drawing”The UI Drawing component (comp-ui-drawing) shows a 2D canvas in a panel. Scripts draw on it with the standard Canvas 2D API: paint tools, minimaps, charts, pictures made at runtime. Entity: UI Drawing (ent-ui-drawing).
| Prop | Type | Default | Description |
|---|---|---|---|
width, height |
number | 256 |
Surface size in layout px. |
resolution |
number | 1 |
Canvas pixels per layout px, 1 to 4. 2 keeps a drawing sharp up close and in VR, for four times the memory. |
background |
string | '#ffffff' |
Colour clear() fills with; 'transparent' clears to nothing. |
cursor |
'crosshair', 'pointer', 'default' |
'crosshair' |
Cursor over the canvas. pointer suits buttons drawn on it. |
borderRadius |
number or number[] | 0 |
Corner radius in px, clipping the canvas. Half the width makes a round minimap. |
padding, margin |
number or number[] | none | In px. |
Draw API
Section titled “Draw API”| Member | What it does |
|---|---|
draw(paint) |
Runs paint(ctx) with the canvas’s 2D context, then shows the result on the next frame, however many draws come before it. |
clear() |
Fills the canvas with background, or clears it when that is 'transparent'. |
canvas |
The canvas element, to copy it into another canvas with drawImage. |
- Coordinates. Each
drawstarts the context in layout px, so you draw at the same coordinates whatever theresolution. - Lifetime. The drawing survives rebuilds of its panel. Changing its size or resolution starts a new, blank canvas, as an HTML canvas does.
- Cost. An idle canvas costs nothing per frame. When you redraw every frame, pass one named function to
drawrather than a new arrow function each time. - It has no border; put it in a UI Panel to frame it.
Pointer events
Section titled “Pointer events”With a Signal Emitter on its entity, the canvas takes the pointer and sends these events, in VR too. x and y are layout px from the canvas’s top-left corner. Without a Signal Emitter the canvas ignores the pointer.
| Event | EventType |
Sent when |
|---|---|---|
UIDrawing::pointer- |
Event |
A pointer presses the canvas. |
UIDrawing::pointer- |
Event |
It moves while pressed. The press is captured, so x and y can leave the canvas. |
UIDrawing::pointer- |
Event |
It lets go. |
UIDrawing::pointer- |
Event |
A pointer moves over it without pressing. Touch has no hover. |
UIDrawing::pointer- |
Event |
The pointer leaves, at the last point it was over. |
Each sends { x, y, pointerId }. pointerId tells two pointers apart, such as two fingers or two controllers.
UI Render View and UI Render Scene
Section titled “UI Render View and UI Render Scene”A UI Render View shows a small 3D world inside a panel: a model turning in a HUD, a character preview, an item in an inventory. The view is the UI Render View entity (ent-ui-render-view); the world it shows is the UI Render Scene entity (ent-ui-render-scene), its child.
UI Panel└── UI Render View the picture: size and quality └── UI Render Scene the world: camera, lights, background ├── Preview Model (a glTF model) └── Behavior turns the modelThe UI Render View component (comp-ui-render-view) is sized like an image:
| Prop | Type | Default | Description |
|---|---|---|---|
width, height |
number | 256 |
Size in px. |
quality |
'low', 'medium', 'high' |
'medium' |
Picture resolution on its long side: 256, 512 or 1024 pixels. |
borderRadius |
number or number[] | 0 |
Corner radius in px. |
padding, margin |
number or number[] | none | In px. |
The UI Render Scene component (comp-ui-render-scene) gives the small world its own camera and lights. The camera sits on the scene’s +Z axis at distance, looking at its origin; a key light, a fill light and an ambient light light it.
| Prop | Type | Default | Description |
|---|---|---|---|
fov |
number | 30 |
Vertical field of view of the camera, in degrees. |
distance |
number | 3 |
Distance of the camera from the origin, in metres. |
background |
string | 'transparent' |
'transparent', or the colour behind the scene. |
- What it holds. Primitives, models (glTF, FBX, OBJ, USDZ, Collada, kit pieces) and Behaviors, nested at any depth. Adding any other kind of entity to it throws.
- Its own world. Everything in it is drawn only in its view: the main camera, shadows and reflections never see it, and the world’s lights never reach it. You still select and edit its entities in the editor.
- Turning a model. Turn the model, not the render scene: the camera follows the scene.
- Cost. While on screen, the view draws its small world once per frame, one extra draw per mesh in it. A hidden or off-screen view draws nothing.
Examples
Section titled “Examples”1. An image gallery
Section titled “1. An image gallery”#pragma lifecycle(startup)
// Scene: a UI Panel with a UI Image named 'Photo' (Signal Emitter: 'gallery:photo'),// a UI Label named 'Caption', and two UI Buttons named 'Previous' and 'Next'// (Signal Emitters: 'gallery:prev' and 'gallery:next').const PHOTOS = [ { src: '/example-assets/lemon-decal.png', caption: 'Lemon slice' }, { src: '/example-assets/bang.png', caption: 'Comic bang' }, { src: '/example-assets/alpha.png', caption: 'Star burst' },];let index = 0;let photo;let caption;
function show() { photo.setProps({ src: PHOTOS[index].src }); caption.setProps({ text: 'Loading…' });}
function startup() { photo = findEntity('Photo').getComponent(UIImageComponent); caption = findEntity('Caption').getComponent(UILabelComponent); photo.setProps({ width: 320, height: 200, objectFit: 'cover', borderRadius: 12 });
on('gallery:photo', (event) => { if (event.eventType === EventType.UIImage.Ready) caption.setProps({ text: PHOTOS[index].caption }); if (event.eventType === EventType.UIImage.Error) caption.setProps({ text: 'Could not load this photo.' }); }); on('gallery:prev', (event) => { if (event.eventType !== EventType.UIButton.Press) return; index = (index + PHOTOS.length - 1) % PHOTOS.length; show(); }); on('gallery:next', (event) => { if (event.eventType !== EventType.UIButton.Press) return; index = (index + 1) % PHOTOS.length; show(); });
show();}A UI Image steps through three pictures with Previous and Next; the caption waits for the image’s ready event and reports load errors.
Press Next and Previous to step through the pictures. Drag outside the panel to orbit the camera, scroll to zoom.
How it works:
- Setting
srcloads a new picture; the fixedwidthandheightwithobjectFit: 'cover'keep the box the same size whatever the photo’s proportions. - The caption says “Loading…” until
UIImage::readyarrives, and reports a failure onUIImage::error. - The listeners are registered in
startupbefore anything else happens, so the firstreadyevent is not missed.
2. A video player
Section titled “2. A video player”#pragma lifecycle(startup)
function startup() { const video = findEntity('Screen').getComponent(UIVideoComponent); const button = findEntity('PlayPause').getComponent(UIToggleButtonComponent); const volume = findEntity('TV Volume').getComponent(UISliderComponent);
on('tv:play', (event) => { if (event.eventType !== EventType.UIToggleButton.Change) return; if (event.data.checked) { video.setProps({ muted: false }); video.play(); } else { video.pause(); } });
on('tv:volume', (event) => { if (event.eventType === EventType.UISlider.Change) video.setVolume(event.data.value / 100); });
on('tv:video', (event) => { if (event.eventType === EventType.UIVideo.Ready) log('video length', event.data.duration, 's'); if (event.eventType === EventType.UIVideo.Play) button.setProps({ text: 'Pause' }); if (event.eventType === EventType.UIVideo.Pause) button.setProps({ text: 'Play' }); if (event.eventType === EventType.UIVideo.End) button.setChecked(false); });
volume.setValue(video.getVolume() * 100);}A UI Video in a panel with a UI Toggle Button that plays and pauses it and a volume slider; the button's label follows the video's own play and pause events.
Press Play to start the video with sound, press again to pause, and drag the slider to change the volume. Drag outside the panel to orbit the camera, scroll to zoom.
How it works:
- The toggle button latches:
checkedis true while it should play. The script unmutes on the first play, which happens after a user’s press, so the browser allows sound. - The button’s label follows the video’s own
playandpauseevents, so it stays right even when something else starts or pauses the video. - At the end of a video set to play
once,UIVideo::endresets the toggle.setChecked(false)sends achangeevent that callspause(), which is harmless at the end.
3. A paint canvas
Section titled “3. A paint canvas”#pragma lifecycle(startup)
const strokes = new Map(); // pointerId -> last point
function startup() { const paint = findEntity('Paint').getComponent(UIDrawingComponent); paint.setProps({ width: 400, height: 300, resolution: 2 });
on('paint', (event) => { const { x, y, pointerId } = event.data; if (event.eventType === EventType.UIDrawing.PointerDown) { strokes.set(pointerId, { x, y }); } else if (event.eventType === EventType.UIDrawing.PointerMove && strokes.has(pointerId)) { const from = strokes.get(pointerId); strokes.set(pointerId, { x, y }); paint.draw((ctx) => { ctx.strokeStyle = '#2563eb'; ctx.lineWidth = 4; ctx.lineCap = 'round'; ctx.beginPath(); ctx.moveTo(from.x, from.y); ctx.lineTo(x, y); ctx.stroke(); }); } else if (event.eventType === EventType.UIDrawing.PointerUp) { strokes.delete(pointerId); } });
on('paint/clear', (event) => { if (event.eventType === EventType.UIButton.Press) paint.clear(); });}A UI Drawing takes the pointer and draws a line for each pointer with Canvas 2D calls; a UI Button clears it.
Draw on the white canvas with the mouse or a finger, then press Clear.
How it works:
- The drawing’s Signal Emitter makes it take the pointer. Each press, move and release arrives with the point in layout px.
- The script keeps the last point of each pointer in a
Mapkeyed bypointerId, so two fingers or two XR controllers draw two separate lines. - Each move draws one short segment with the standard Canvas 2D calls.
resolution: 2keeps the lines sharp up close. clear()fills the canvas with itsbackgroundcolour.
4. A round minimap
Section titled “4. A round minimap”#pragma lifecycle(startup, update)
// Scene: a HUD panel with a UI Drawing named 'Minimap',// and an entity named 'Player' that moves around a 40 m square level.const SIZE = 160; // layout pxconst WORLD = 40; // metres shown across the maplet map;let player;
function startup() { map = findEntity('Minimap').getComponent(UIDrawingComponent); map.setProps({ width: SIZE, height: SIZE, borderRadius: SIZE / 2, background: '#0f172a' }); player = findEntity('Player');}
function drawMap(ctx) { map.clear(); const x = SIZE / 2 + (player.position.x / WORLD) * SIZE; const y = SIZE / 2 + (player.position.z / WORLD) * SIZE; ctx.fillStyle = '#f87171'; ctx.beginPath(); ctx.arc(x, y, 5, 0, M_TAU); ctx.fill();}
function update() { map.draw(drawMap);}Every frame a script redraws a round UI Drawing in the corner of the screen with a dot at the player's position on a 40 m map.
Watch the red dot on the minimap follow the amber player around the yard. Drag to orbit the camera, scroll to zoom.
How it works:
borderRadiusat half the width clips the canvas into a circle.updateruns every frame and redraws with one named function,drawMap, instead of creating a new function each frame.- The player’s x and z are mapped from metres to layout px around the map’s centre.
M_TAUis a full turn in radians.
5. A turntable preview
Section titled “5. A turntable preview”#pragma lifecycle(startup, update)
const SPEED = 0.6; // radians a secondlet model;let scene3d;
function startup() { model = findEntity('Preview Model'); scene3d = model.parent.getComponent(UIRenderSceneComponent); scene3d.setProps({ distance: 2.5, fov: 35, background: 'transparent' });}
function update(dt) { model.rotation.y += dt * SPEED;}A character preview inside a panel: a UI Render View shows a UI Render Scene with its own camera and lights, and a Behavior turns the model in it.
Watch Amelia turn inside the panel: she lives in the render scene, lit by its own lights. Drag outside the panel to orbit the camera, scroll to zoom.
How it works:
- The model lives inside the UI Render Scene, so it is drawn only in the panel’s view, lit by the render scene’s own lights.
- The script turns the model, not the scene: the render scene’s camera is fixed to the scene, looking at its origin from
distancemetres away. model.parentis the UI Render Scene entity here, because the model is its direct child.
Snippets
Section titled “Snippets”1. A score label
Section titled “1. A score label”#pragma lifecycle(startup)
// Scene: a UI Label named 'Score'. Other scripts emit 'game:point' with// the number of points scored, for example emit('game:point', 10).let score = 0;
function startup() { const label = findEntity('Score').getComponent(UILabelComponent); label.setProps({ fontSize: 32, fontWeight: 'bold', padding: [6, 14], backgroundColor: '#1e293b', borderRadius: 10 });
on('game:point', (points) => { score += points; label.setProps({ text: `Score: ${score}`, color: score >= 100 ? '#facc15' : '#ffffff' }); });}How it works:
setPropsstyles the label’s box: padding of 6 px above and below and 14 px on the sides, a fill and rounded corners.- A signal raised with
emit(signal, data)passesdatastraight to theoncallback, sopointsis the number another script sent. - The colour switches to gold once the score reaches 100; the label resizes around its text by itself.
Common mistakes
Section titled “Common mistakes”- A label that never wraps. Without
maxWidth(orwidth), a label is one line however long its text. Set a width to make it wrap. - Images and videos that never report. Without a Signal Emitter on the element,
ready,errorandpressare not sent. - Missing the first
ready. Register listeners instartupbefore anyawait, or the first event can arrive before you listen. - Video that stays silent.
mutedis true by default because browsers block sound before the user interacts. Unmute after a press. - Drawing on a canvas without a Signal Emitter. The canvas ignores the pointer until it has one.
- A new closure every frame.
map.draw(() => …)inupdatecreates a function per frame. Pass a named function. - Putting lights or cameras in a UI Render Scene. It accepts only primitives, models and Behaviors, and has its own camera and lights.