Placement and fonts
Updated
This page answers two practical questions. First, where does a UI element end up? It depends only on its parent: inside a panel it is laid out, under a 3D object it floats in the world. Second, what does its text look like? Every piece of UI text draws with a font family chosen by name, from the families that ship with the runtime, the project’s own, or ones a script registers at run time with Fonts.
Before you start
Section titled “Before you start”- Read the UI overview for roots and nested elements.
- Labels are covered in Content; spacing in Panels and layout.
- Billboard, which turns an object to face the camera, is covered in Common components and its reference page.
Placement
Section titled “Placement”Any UI element can go anywhere in the hierarchy; nothing is rejected for its parent. Where it goes decides how it is placed:
| Parent | The element is |
|---|---|
| A 3D object, or the scene root | The root of its own UI, drawn in the world at its entity’s transform, at pixelSize metres per layout pixel (0.003 m by default). It moves with its parent. Scale the entity to size it. |
| A UI Layout or UI Panel | Laid out inside it by the parent’s layout. |
| A control (a button, a label…) | Taken into the control’s own box. |
| A control with a UI Menu | Put into the menu’s popup. See Controls. |
- Transform. A nested element’s Transform has no effect, and neither does a root’s under UI Screen Space. The editor disables their transform fields and gizmo and says why.
- Only the direct parent counts. A UI element under a plain Group under a panel is a root of its own, not part of the panel’s layout.
- Order. Children are laid out in hierarchy order.
- Cost. Each free-standing root is its own tree with its own layout and drawing. Many elements under one panel cost less than as many separate roots.
- Across scenes. A UI Panel takes a Don’t Unload component, for a HUD or inventory kept across scene switches; its controls travel with it.
A label pinned to an object
Section titled “A label pinned to an object”A label that floats over an object is a UI Label placed under that object, raised above it, and turned to the camera by a Billboard component. Because it is a child of the object, it follows the object wherever it moves. A Billboard on a UI root turns the drawn UI, never the saved transform, so it also works while you edit.
UI Label box
Section titled “UI Label box”A UI Label draws its text inside a box styled with CSS names:
paddingis the space inside the box, 1 px by default;marginthe space outside it, none by default. Both take one number or one to four, clockwise from the top.backgroundColorandborderRadiusfill the box and round its corners.borderColorandborderWidthdraw a solid border, only whenborderColoris set. Its width defaults to 2 px. Like a CSS border, it takes space inside the box.width,maxWidth,minHeightandmaxHeightsize the box; text pastmaxHeightis clipped or scrolls, peroverflow.
Long unspaced text
Section titled “Long unspaced text”A label wraps at word boundaries. A long run with no spaces, such as a URL or a code, can overflow a narrow panel. Give the label a width or maxWidth and set overflowWrap: true: it keeps normal word wrapping and breaks inside a word only when that word is wider than the label. For full control, wordBreak takes 'break-word', 'break-all' (break anywhere) or 'keep-all' (never inside a word, which wins over overflowWrap). Wrapped text grows the label; cap it with maxHeight and overflow: 'hidden' or 'scroll'.
Every text renderer picks its font from one list of font families, by name, through its font prop: UI text (labels, buttons, controls, notifications, the AI caption and dialog), world-space Text and Text 3D, and the ASCII effect. A family is a typeface such as Inter, available in one or more weights ('light', 'normal', 'medium', 'semi-bold', 'bold').
Five families ship with the runtime:
| Family | Look | Weights | Characters |
|---|---|---|---|
inter (default) |
Neutral sans | light, normal, medium, semi-bold, bold | Latin with accents, Greek, Cyrillic, punctuation, currencies, arrows and symbols such as ✓ ✗ ★ ♥ |
roboto |
System-style sans | normal, bold | Latin with accents, typographic punctuation, currency and signs |
nunito |
Rounded, friendly | normal, bold | As Roboto |
montserrat |
Geometric display | normal, bold | As Roboto, plus arrows |
jetbrains- |
Monospace | normal, bold | As Roboto, plus arrows, ✓ ✗ |
Every family has accented Latin letters, ñ, ¿ ¡, typographic punctuation (… – — “ ” ‘ ’ • ·) and common signs (€ £ ¥ © ® ™ ± × ÷).
- The default. The project’s theme sets the font for the whole UI; unset, it is Inter. A UI Label or UI Button takes its own
font, and a notification theme takesfontFamily. - A family not registered. UI text naming a family that is not registered yet draws in Inter, and switches when the family registers. Every open UI rebuilds once when a family is registered or removed.
- Loading. A weight loads the first time some text uses it, so unused fonts cost nothing, and a scene without UI text loads none.
- A project’s own fonts. A project can save font families of its own; they appear in the list like the bundled ones and are named the same way.
Emojis
Section titled “Emojis”Emojis in UI text draw in colour, inline with the letters, in every family: labels, buttons, notifications, tooltips and text inputs. That includes flags, keycaps and joined sequences such as 👨👩👧. Skin-tone variants draw with the default yellow tone. An emoji is about the size of the font; color does not tint it, while opacity and fading apply. A scene whose text has no emoji downloads nothing for them. World-space Text and Text 3D draw no emojis. The emoji images are licensed under CC-BY 4.0: credit them in your product’s credits. See Emoji moods.
Fonts at run time
Section titled “Fonts at run time”The Fonts global registers a font file as a family for the session. Every text whose font names that family draws with it from then on.
| Global | What it is |
|---|---|
Fonts | The app's font families: await Fonts.register(family, url, { weight, label }) for this session, unregister, has(family), families. |
| Member | What it does |
|---|---|
await Fonts. |
Load a .ttf, .otf or .woff file and register it as family, in the weight slot ('normal' by default). label is the name an editor shows. Registering the same family and weight again replaces it. Rejects when the file is not a usable font, or family is a bundled family or not a name of 1 to 64 characters. |
Fonts. |
Remove a registered family, or one the project saves, until the project loads again; texts using it go back to their default. Returns false for a bundled or unknown family. |
Fonts. |
Whether family can be drawn with now. |
Fonts. |
Every family as { name, label, look }, the bundled ones first. |
- A registered family lasts for the session, after the script is released too, and is never saved. Every player runs the same scripts, so each registers it on their own device.
- A family missing a weight draws with the nearest one it has.
Examples
Section titled “Examples”1. A floating name tag
Section titled “1. A floating name tag”#pragma lifecycle(startup)
function startup() { const box = findEntity('Lemon Box');
const tag = new UILabelEntity(); tag.getComponent(UILabelComponent).setProps({ text: 'Lemon Box', fontSize: 40, padding: 12, backgroundColor: 'rgba(28, 28, 30, 0.9)', borderRadius: 14, borderColor: '#69ebed', }); tag.position.set(0, 0.8, 0); tag.addComponent(new BillboardComponent());
box.add(tag);}A styled label pinned above a box that always turns to face the camera: a UI Label entity created by a Behavior script, with a Billboard, added under the mesh.
Orbit around the box: the tag keeps facing you. Drag to orbit the camera, scroll to zoom.
How it works:
- The label is added under the box, so it is a root of its own placed by its own transform, 0.8 m above the box’s origin, and it moves with the box.
- The Billboard turns the label to face the camera wherever the player stands.
- The box styling (padding, fill, rounded corners, border) comes from the label’s own props.
2. Emoji moods
Section titled “2. Emoji moods”Emojis are ordinary characters in UI text. Each button’s text is one emotion emoji; pressing one copies it into the big label.
#pragma lifecycle(startup)
function startup() { const mood = findEntity('Mood').getComponent(UILabelComponent); on('mood:pick', (event) => { const emoji = findEntity(event.entityId).getComponent(UIButtonComponent).props.text; mood.setProps({ text: emoji }); log('Mood:', emoji); });}Emojis in UI text: a label and buttons whose text is an emotion emoji. Each button copies its emoji into the big label.
Press a face to show that mood large on the card. Drag outside the card to orbit the camera, scroll to zoom.
- The big label is the same emoji at a larger
fontSize: an emoji is sized like the letters around it.
3. Name tags for every object in a group
Section titled “3. Name tags for every object in a group”#pragma lifecycle(startup)
// Scene: a Group named 'Exhibits' whose children are the objects to label.// Each child's name becomes its tag.function makeTag(text) { const tag = new UILabelEntity(); tag.getComponent(UILabelComponent).setProps({ text, fontSize: 28, font: 'nunito', padding: [6, 12], backgroundColor: '#0f172a', borderRadius: 10, }); tag.addComponent(new BillboardComponent()); return tag;}
function startup() { const exhibits = findEntity('Exhibits'); for (const child of [...exhibits.children]) { if (!isEntity(child)) continue; const tag = makeTag(child.name); tag.position.set(0, 1.2, 0); child.add(tag); }}A script gives every child of the Exhibits group a billboard UI Label with the child’s name, floating above it.
Drag to orbit the camera: the tags keep facing you. Scroll to zoom.
How it works:
- The loop copies the children list first (
[...exhibits.children]), because adding tags changes the hierarchy while it is being walked. isEntityskips plain objects that are not entities, such as meshes inside a model.- Each tag uses the bundled
nunitofamily through itsfontprop.
4. A font picker
Section titled “4. A font picker”#pragma lifecycle(startup)
// Scene: a UI Label named 'Sample' and a UI Button named 'Next Font'// with a Signal Emitter on 'fonts/next'.let index = 0;
function startup() { const sample = findEntity('Sample').getComponent(UILabelComponent); const button = findEntity('Next Font').getComponent(UIButtonComponent);
function apply() { const families = Fonts.families; const family = families[index % families.length]; sample.setProps({ text: `${family.label}: The quick brown fox`, font: family.name }); button.setText(`Font ${(index % families.length) + 1} of ${families.length}`); }
on('fonts/next', (event) => { if (event.eventType !== EventType.UIButton.Press) return; index += 1; apply(); });
apply();}Each press of the button shows the sample line in the next family of Fonts.families, with its label, and counts through the list.
Press the button to step through the fonts. Drag outside the panel to orbit the camera, scroll to zoom.
How it works:
Fonts.familieslists every family, bundled ones first, each with anameto put infontand a readablelabel.- The list is read again on each press, so families registered later by another script appear too.
5. A long link that stays inside its panel
Section titled “5. A long link that stays inside its panel”#pragma lifecycle(startup)
// Scene: a UI Panel 320 px wide with a UI Label named 'Link'.function startup() { const link = findEntity('Link').getComponent(UILabelComponent); link.setProps({ text: 'https://example.com/rooms/7f3a9c21b4e84d0f9a6e/invite?from=lobby', font: 'jetbrains-mono', fontSize: 14, maxWidth: 280, overflowWrap: true, maxHeight: 60, overflow: 'hidden', });}A long link in a monospaced font wraps anywhere inside a 280 px width, and is clipped at 60 px high, so it never spills out of its panel.
See the long link wrap inside the panel. Drag outside the panel to orbit the camera, scroll to zoom.
How it works:
maxWidthgives the label a width to wrap at, andoverflowWrap: truelets it break inside the long URL, which has no spaces.maxHeightwithoverflow: 'hidden'caps the label at about three lines, so a very long link cannot push the panel’s other content away.
Snippets
Section titled “Snippets”1. Registering a font at run time
Section titled “1. Registering a font at run time”#pragma lifecycle(startup)
// Scene: a UI Label named 'Headline'. The project ships the font files// /assets/Branda.ttf and /assets/Branda-Bold.ttf.async function startup() { const headline = findEntity('Headline').getComponent(UILabelComponent); headline.setProps({ text: 'Grand Opening', fontSize: 48, font: 'branda' });
try { await Fonts.register('branda', '/assets/Branda.ttf', { label: 'Branda' }); await Fonts.register('branda', '/assets/Branda-Bold.ttf', { weight: 'bold' }); headline.setProps({ fontWeight: 'bold' }); } catch (error) { log('Branda could not load, keeping the default font:', error.message); headline.setProps({ font: 'montserrat' }); }}How it works:
- The label names
brandabefore the family exists; it draws in Inter until the family registers, then switches by itself. - Each
registercall fills one weight slot of the family:normalfirst, thenbold. registerrejects when the file is not a font it can use. Thecatchfalls back to a bundled family instead of leaving the error unhandled, which would stop the script.
Common mistakes
Section titled “Common mistakes”- A UI element under a Group inside a panel. Only the direct parent counts; it becomes a separate root. Put UI directly under the panel or a UI Layout.
- Moving a nested element by its position. The layout places it. Move it with layout props, or make it a root.
- Forgetting the Billboard. A pinned label without one keeps its own rotation and is unreadable from behind.
- Characters that do not show. The bundled fonts do not cover Arabic, Hebrew, Indic or CJK scripts. Choose content the fonts cover.
- An unhandled
registerfailure.Fonts.registerreturns a promise that rejects on a bad file.awaitit insidetry/catchin an async hook. - Expecting a run-time font to be saved. A family registered with
Fontslasts for the session only; a font the project should keep belongs in the project’s own fonts.