Skip to main content

Game UI (menus & HUD)

Scores, lives, health bars, pause buttons, title screens and game-over menus are UI elements: objects with a UI element component, drawn flat on top of the game (or placed in the 3D world, see World Canvas).

The UI follows Unity's uGUI on purpose, with the same names: Canvas, Canvas Scaler, Rect Transform, Raycast target, Interactable, Transition, Layout group. If you know a Unity tutorial for the UI, the settings are where it says.

Add UI​

Objects β†’ οΌ‹ Add, in the UI group:

The UI group of the Add menu
The UI group of the Add menu
ItemUse for
🏷️ TextText on screen: score, lives, messages.
πŸ”² ButtonA tappable button: Start, Pause, Retry… An Image with a Button component and a Text inside it for the label.
β˜‘οΈ ToggleA checkbox, or radio buttons with a Toggle group. See Toggles.
πŸ–ΌοΈ ImageAn icon or picture.
πŸ”½ DropdownA list to pick one option from: quality, language, resolution. See Dropdowns.
πŸ“Š SliderA bar, or a value you can drag: health, energy, volume.
⌨️ Input fieldA box the player types in: a name, a chat line, a code. See Input fields.
🌐 HTMLYour own HTML and CSS: forms, tables, rich text. See HTML element.
πŸͺŸ PanelA box that holds other UI elements.
πŸ“± Screen (menu)A full-screen panel: title screen, pause menu, game over.
πŸ–ΌοΈ CanvasThe surface the UI is drawn on. Made for you with the first element.
🌐 World CanvasA canvas that stands in the 3D scene (name tags, signs, a screen on a wall).

Like Unity, the first UI element you add creates a Canvas around itself. UI added while a canvas, panel or screen is selected goes inside it (it becomes a child).

UI mode​

When you select a UI element, the 3D view switches to UI mode: it shows the game screen as a frame, at the size of the canvas's reference resolution. Tap an element to select it, drag to move it and pull the orange corner handle to resize it. The UI button in the viewport toolbar switches UI mode on and off; Snap moves in 8 px steps.

A button in UI mode
A button in UI mode
A slider
A slider

Canvas​

Every UI element lives inside a Canvas, which decides where the UI is drawn.

Canvas, Screen Space - Overlay
Canvas, Screen Space - Overlay
FieldWhat it does
Render modeScreen Space - Overlay: flat on top of the game. World Space: a panel in the scene.
Sort orderA higher canvas is drawn on top of a lower one.
First selectedThe button or slider a controller or the arrow keys start from. None: this canvas's UI works with the mouse and touch only. See Controller and keyboard.

Canvas Scaler​

An overlay canvas has a Canvas Scaler, which keeps the UI the same shape on every screen. Every pixel you type anywhere in the UI is a pixel of its reference resolution.

FieldWhat it does
UI scale modeScale with screen size (the usual choice) or Constant pixel size.
Reference resolutionThe screen size you design for. New projects use 740 Γ— 360 (landscape) or 360 Γ— 740 (portrait).
Screen match modeHow the reference is fitted to the real screen: Expand (everything stays visible), Shrink (fills the screen, may crop), or Match width or height.
MatchWith Match width or height: 0 follows the width, 1 follows the height.
Scale factorWith Constant pixel size: how many screen pixels one UI pixel takes.

World Canvas​

Canvas, World Space
Canvas, World Space
FieldWhat it does
Face the cameraOn: a flat label that turns to the camera and keeps its size on screen, like a health bar over an enemy. Off: a panel that stands in the scene where you put it and turns with its object.
Size (px)The width and height of the canvas, in UI pixels. Elements are placed inside this box.
Pixels per metre(Standing canvas) How many UI pixels make one metre in the world.
Height offset (m)(Facing the camera) How far above the object it floats.

To put a health bar over an enemy, add a World Canvas and drag it onto the enemy in the Objects list so it is a child, turn on Face the camera, and add a Slider inside it.

Rect Transform​

A UI element is placed by its Rect Transform, exactly as in Unity.

Rect Transform
Rect Transform
  • Anchors: tap one of the presets. The 3 Γ— 3 dots pin the element to a corner, an edge or the middle of its parent, so a score anchored top-left stays in the top-left on a small phone and on a tablet. The bars on the right and bottom stretch the element across the parent.
  • Also set (Pivot / Position): choose whether tapping a preset also moves the pivot and the position to match, as holding Shift and Alt does in Unity.
  • Pos X / Pos Y and Width / Height: where the pivot sits relative to the anchor, and the size. With a stretched anchor these become Left, Right, Top, Bottom, the distances from the parent's edges.
  • Pivot: the point the element turns and scales around, 0 to 1 from its bottom-left.
  • Rotation (degrees, counter-clockwise) and Scale.
  • Content size fitter: size the element to its text. See Sizing.
  • Sort order: a higher number is drawn on top of its siblings.

Y counts up, as in Unity: a Pos Y of βˆ’16 is 16 pixels below the anchor.

Text, Image, Slider, Panel and Input field​

The card shows the fields of the Type you picked. You can change the type later.

Text
Text
Image
Image
Slider
Slider
Panel
Panel
Screen
Screen

Look​

FieldWhat it does
Text / CaptionThe words. A button's label is a Text object inside it.
Raycast targetWhether the element receives taps. Turn it off on decoration that should let taps through.
Background image, Background, Background opacityA picture or a color behind the element; opacity 0 = transparent.
Image typeSimple, Sliced (9-slice) (corners stay sharp when stretched, with a Border), Tiled, or Filled (a clock-wipe or a bar, driven by Fill method, Fill amount, Clockwise). Preserve aspect keeps the picture's proportions.
Corner radius, Border width, Border colorThe shape of the box.
OpacityOf the element and everything inside it.
FontThe font of the text: one you imported, a free one, or None for the default font. See Fonts.
Font size, Bold, Italic, Text colorText style.
Align, Vertical align, Wrap, Line spacingWhere the text sits and how it wraps.
Rich textTags such as <b> and <color=red> style parts of the text. See Rich text.

Fonts​

Tap Font on anything with text (a Text, a button's label, a slider's caption; the Text component has it too) and choose:

  • a font already in the project,
  • Import new… for a font file from your phone (TTF, OTF, WOFF or WOFF2),
  • Free fonts… for the twelve built-in Kenney fonts, free to use in your games (CC0). Each name in the list is drawn in its own font.

A free font is copied into the project when you pick it, so it works offline and travels with an exported game, like any other file. In the Files tab a font is shown as Aa drawn in that font.

Fonts load with the scene, so text never appears in the default font first. That includes a font that only an event or a script names (Set font, setUIFont('Kenney Pixel')).

Most game fonts have one weight; Bold and Italic on them are made by the browser (thicker and slanted), which suits some fonts better than others.

Change it while playing with the Set font action, or entity.setUIFont('Kenney Pixel') in a script ('' goes back to the default font). Deleting a font from Files sets the text that used it back to the default.

Slider values​

FieldWhat it does
Value / Min / MaxHow full it is.
Whole numbersSnap to whole numbers.
DirectionLeft to right, right to left, bottom to top, top to bottom.
Fill colorThe color of the filled part.
Handle, Handle colorA draggable knob. Off for a plain bar such as health. Tapping or dragging a slider with a handle changes its value.

Interaction​

For sliders, and for anything with a Button component (see Buttons):

FieldWhat it does
InteractableOff greys it out and it takes no input.
TransitionHow it reacts: None, Color tint (colors for normal, highlighted, pressed, selected and disabled, with a Color multiplier and Fade duration) or Sprite swap (a different picture for highlighted, pressed, selected and disabled). Selected is how it looks when a controller or the arrow keys have chosen it; left alone it is the highlighted look.
NavigationAutomatic: a controller or the arrow keys can move to it. None: they skip it.

Sprite sheets in an Image​

If the Source image is a picture made in the sprite editor with several frames, the Image card shows a Frame field (which frame to show), and Play frames with an Animation (all frames, or one of the sprite's named animations), Loop and Speed. Size the Image to one frame's proportions; the frame fills the element. Frame settings apply to Simple and Filled images, not to sliced or tiled ones.

From events and scripts the same actions as for a Sprite work on an Image: Show frame … of …, Play animation, Stop animation, Set animation speed and the Is playing animation condition; in code setSpriteFrame(n), playAnimation('spin'), stopAnimation().

Pictures load with the scene​

Every picture an element uses (its image, mask, a Button's sprite-swap pictures) is loaded and decoded while the scene loads, so a menu never opens with blank boxes. A picture that only an event or script puts on screen (Set image to…, setUIImage('Coin')) is found by its name or id in your events and scripts and loaded with the scene too. When you change scenes, the new scene appears once its pictures, models and sounds have loaded; use a loading screen scene to show progress meanwhile.

Rich text​

With Rich text on (it is for new texts), tags in the text style parts of it, as in Unity:

TagDoes
<b>…</b>, <i>…</i>Bold, italic.
<u>…</u>, <s>…</s>Underline, strike through.
<color=#ffd54f>…</color> or <color=red>Colour (a hex colour or a colour name).
<size=40>…</size>Size in reference px; <size=150%> scales, <size=+4> adds.
<mark=#ffff0080>…</mark>A highlight behind the text.
<sup>…</sup>, <sub>…</sub>Raised or lowered, smaller.
<br>A new line.
<prompt=jump>A control button's key or gamepad button for the device in use (Button prompts).

Score: <color=#ffd54f><b>120</b></color>. Any other tag shows as written, so a name a player typed can't break the label, and Input fields never use rich text. An event's text works the same: Set label to "Coins: <b>" + Coins + "</b>".

Buttons​

As in Unity, a Button is a component you add to a UI element, not a type of element. οΌ‹ Add β†’ UI β†’ Button makes an Image with a Button component and a Text for its label. To turn something else into a button, select an Image, Panel or Text and tap Add component β†’ Button. Anything that has a Button can be tapped, tinted or swapped when pressed, and used with the On clicked event.

The Button card has two parts:

  • Interaction β€” Interactable and Transition, as above.
  • On Click () β€” what a tap does, a list run in order. Tap οΌ‹ Add and choose:
FieldWhat it does
ObjectThe object it acts on: this one, or any other object of the scene.
DoRun function, Set active or Set visible.
Script, Function(Run function) One of the code scripts on that object, and a function written in it. Every function at the top level of the script is listed; hooks such as update and names that start with _ are not.
Argument(Run function) Optional: a number (5), true / false, or text. It is handed to the function.
Active / Visible(Set active / Set visible) Turns the object on or off, so a menu opens and closes with no code.
// On the Door object's code script
function openDoor(speed) {
entity.tween('y', 4, speed);
}

Choose Door β†’ Door script β†’ openDoor() with the argument 2 and the button opens the door. The same click still triggers On clicked events and the script's own onClick().

Old projects are converted when they open: each button becomes an Image with a Button component, and a label it drew itself becomes a child Text.

Toggles​

A Toggle is something that is on or off: a checkbox (Music, Subtitles, Invert Y) or, with a Toggle group, a set of radio buttons (Easy / Normal / Hard). As in Unity it is a component: οΌ‹ Add β†’ UI β†’ Toggle makes a row with a Toggle component, holding a white Background box with a Checkmark inside it, and a Label beside it. Tapping anywhere on the row switches it. You can also select a Panel or Image and tap Add component β†’ Toggle.

Field (Toggle card)What it does
Is onWhether it starts on.
GraphicThe element shown while it is on and hidden while it is off: the Checkmark. Any child works (an icon, a filled dot).
Target graphicThe element that takes the Interaction colors or pictures: the Background box. Empty: the toggle's own element.
Toggle transitionFade: the graphic fades in and out. None: it snaps.
GroupAn object with a Toggle group (below). Turning this toggle on turns the others in that group off.
InteractionInteractable, Transition and Navigation, as for a button.
On Value Changed (Boolean)A list run every time it switches, like a button's On Click (). Set active and Set visible can follow the toggle (Is on), so a Show FPS toggle shows and hides the FPS label with no code; a function with no argument gets true or false.
EventWhen
On value changed ⚑It switched, by a tap, a controller or Set toggle. Each toggle a group turns off gets one too.
Is onIt is on right now.
Set toggle (action)Turns it on, off, or switches it, as a tap would (its group follows).

Music.value is 1 while on and 0 while off. Set label changes the text of its Label.

In scripts: entity.isToggleOn(), entity.setToggleOn(true), and the hook onValueChanged(value), which gets true or false:

// On the Music toggle
function onValueChanged(on) {
game.audio.setMasterVolume(on ? 1 : 0);
}

Toggle group​

For radio buttons, add a Toggle group component to an object (often the panel the toggles sit in) and set each toggle's Group to it. Then at most one of them is on.

FieldWhat it does
Allow switch offOff (the default): one is always on, and tapping the one that is on leaves it on. On: tapping it turns it off, so none may be on.

When the scene starts, a group fixes itself as Unity's does: if several are on, the first keeps it; if none is on and switching off isn't allowed, the first one turns on.

A Dropdown lets the player pick one option from a list: quality, language, resolution, a save slot. Like a button it is a component: οΌ‹ Add β†’ UI β†’ Dropdown makes a white box with a Dropdown component, a Label that shows the chosen option and an Arrow. A tap (or A / Enter on the selected dropdown) opens the list under the box, or above it when there is no room below. Tapping an option picks it; tapping anywhere else closes the list, and that tap goes no further.

Field (Dropdown card)What it does
Caption textThe Text that shows the chosen option: the Label.
ValueThe option chosen at the start.
OptionsThe list, in order. οΌ‹ Add adds one; ↑ moves one up; Γ— removes it.
ListHow the open list looks: Item height, Max height (a longer list scrolls), Font size, List color, Text color and Highlight color (the row under the mouse or the controller). The font is the caption's.
InteractionInteractable, Transition and Navigation, as for a button.
On Value Changed (Int32)A list run every time another option is picked. A function with no argument gets the option's number.

Unlike Unity, the list is drawn by the engine from the List settings, not from a Template object you edit.

Options are numbered from 0. Quality.value is the chosen number and Quality.text its text.

EventWhen
On value changed ⚑Another option was picked, by the player or by Set selected option.
Compare slider valueCompares the chosen number (= 2).
Set selected option (action)Chooses an option by number.
Add option / Clear options (actions)Fill the list while the game runs.

In scripts: entity.getUIValue() / entity.setUIValue(2) (choosing one also runs On value changed), entity.getText(), entity.getUIOptions(), entity.setUIOptions(['Low', 'High']), entity.addUIOption('Ultra'), and the hook onValueChanged(index):

// On the Quality dropdown
function onValueChanged(index) {
game.quality.level = entity.getUIOptions()[index]; // a quality level, by name
}

With a controller: A opens the list on the chosen option, up / down move, A picks, B (or Esc) closes it without picking.

Input fields​

An Input field is a box the player types in, like Unity's Input Field. οΌ‹ Add β†’ UI β†’ Input field makes a white box with a grey Enter text... placeholder. Click or tap it and type: the caret, selecting, copy and paste and a phone's keyboard all work as in any text box, and while the player types, keys don't reach the game (typing a W doesn't walk).

What the player typed is the element's Text: NameBox.text (or NameBox.value) in events, getText() in scripts (getUIValue() gives it as a number, for a number field). Set label (setText()) changes it. Its look is the Text settings: font, size, color, align.

Field (Typing card)What it does
PlaceholderShown greyed out while the box is empty.
Content typeWhat may be typed. Standard: anything. Integer number, Decimal number: digits (a minus sign, one point), and a number keyboard on phones. Alphanumeric: letters and digits. Name: each word starts with a capital. Email address: no spaces, an email keyboard on phones. Password: shown as dots. Pin: digits, shown as dots.
Character limitThe most characters it takes; 0 = no limit.
Multi-lineEnter starts a new line instead of finishing.
Read onlyThe text can be selected and copied, not changed.

It also has the Interaction settings (Interactable, Transition, Navigation), so a controller can reach it.

EventWhen
On submitted ⚑The player pressed Enter (single-line boxes). Use it to send a chat line or accept a name.
On typing finished ⚑The player stopped typing: Enter, a tap or click elsewhere, Esc, or B on a controller.
On value changed ⚑The text changed (every letter).
Is being typed inThe box has the keyboard right now: hold the player still while they type.
Start typing (action)Puts the keyboard in the box, e.g. when a "Your name" panel opens.

In scripts the box's own scripts get onSubmit(text) and onEndEdit(text); entity.focusUI() starts typing, entity.isUIFocused() tells whether the player is typing.

// On the ChatBox input field
function onSubmit(text) {
if (text.trim()) game.net.send('chat', text);
entity.setText('');
}

With a controller: select the box (see below) and press A to type; B stops. On the Steam Deck, and on a PC in Steam's Big Picture mode, Steam's on-screen keyboard opens next to the box, as Valve requires for games that ask for text.

HTML element​

An HTML element draws your own HTML and CSS, like Construct's HTML element. Use it for what the built-in UI does not have: a form with many fields, a table, rich text with links, an embedded video. οΌ‹ Add β†’ UI β†’ HTML makes one with a small card to start from.

Field (UI card β†’ Code)What it does
HTMLThe markup.
CSSStyles for that markup only. They cannot change the rest of your UI or the editor, and the rest cannot change them. The element's Text color and Font are inherited.

Both are code editors with colours, suggestions for tags, attributes and CSS properties, and closing tags typed for you. Drag a box's bottom edge to make it taller, or tap β€’ to edit in a full-size sheet. The scene shows each change as you type.

The element is placed with its Rect Transform like any other, and Raycast target decides whether it takes taps. Taps and typing inside it never reach the game, so a key typed in its text box does not move the player.

In the editor the markup is drawn without scripts or on… handlers, so opening a project never runs its code. In the game it runs as written.

EventWhen
On HTML clicked ⚑Something the CSS selector names was clicked, or something inside it: "#buy", ".item", "button". Leave it empty for anywhere.
On HTML changed ⚑A text box, checkbox or list the selector names was changed.
Set HTML content (action)Sets the content of what the selector names. As text shows exactly what it is given, so a name a player typed can never become markup. As HTML uses it as markup. With an empty selector it replaces the whole element.
Set HTML attribute / Set HTML style / Set HTML class (actions)Set or remove an attribute (src, disabled), set one CSS property, or add, remove or switch a class.

Expressions: Form.htmlValue("#name") (a text box's or list's value, 1 or 0 for a checkbox), Form.htmlText("#score"), Form.htmlAttr("#pic", "src"), and Form.htmlClickedId(), the id of what was clicked (or of the nearest element around it that has one).

In scripts, entity.htmlRoot is the element's shadow root, so the whole DOM API is there:

// On the Form HTML element
function start() {
entity.htmlRoot.querySelector('#name').addEventListener('input', (e) => {
game.setVar('PlayerName', e.target.value);
});
}

entity.setHTML(markup) replaces all of it.

A script on the HTML element also gets two hooks. id is the id of the part clicked or changed, or of the nearest element around it that has one:

function onHTMLClick(id, target) {
if (id === 'play') game.goToScene('Level 1');
}

function onHTMLChange(id, value, target) {
if (id === 'music') game.setVar('Music', value); // 1 or 0 for a checkbox
}

A game script gets them for every HTML element, with the element first: onHTMLClick(element, id, target).

Controllers: a controller and the arrow keys cannot move into an HTML element. On a Steam Deck or a console, use the built-in buttons, toggles, dropdowns and input fields for anything the player must reach.

Controller and keyboard​

Menus work with a gamepad (and the Steam Deck's controls) or the keyboard, as Unity's EventSystem does:

  1. Select the Canvas and set First selected to the button the menu starts on (Play).
  2. That's it. Every button, toggle, dropdown, slider and input field on that canvas can now be reached.
InputWhat it does
Left stick, D-pad, arrow keys (or WASD)Moves to the nearest button or slider in that direction. Held, it repeats.
A, EnterClicks the selected button (On clicked events and its On Click () list run, as for a tap) switches the selected toggle, or opens the selected dropdown.
Left / right on a sliderChanges its value by a tenth of its range, or by 1 with Whole numbers (up / down on a vertical slider).
Along a scrollbarMoves it a tenth, or one step with Number of steps.
  • Nothing shows as selected until the controller or a key is used, and the selection hides again when the mouse moves or a finger touches the screen. Mouse and touch work as before.
  • When a panel closes and the selected button goes with it, the selection moves to the First selected of the canvas on top, or, if that one is hidden too, to the top-left button that can be selected. So a menu with several panels needs nothing more; to choose the button a panel opens on, use Select (events) or selectUI() (scripts) when you show it.
  • New buttons and sliders turn amber when selected, so the player sees where they are on a TV or a Steam Deck. Change Selected color (or use a Selected image) to fit your game. Buttons made before this have no selected color of their own and use the highlighted one.
  • In a Scroll View, the list scrolls to show the selected button when it is out of sight, so a controller can go down a long list. Selecting one with Select or selectUI() does the same.
  • Only canvases with a First selected take part, so a HUD's buttons are never selected by accident. Navigation: None leaves out one button.
  • The same stick and keys still reach your game, so when a pause menu is open, stop the player from moving (for example with Set time scale to 0; menus keep working while the game is paused).

Layout groups​

A Layout group arranges the children of a panel for you, like Unity's Horizontal, Vertical and Grid Layout Groups. Use it for a row of buttons, a list of menu items or an inventory grid.

Layout group on a panel
Layout group on a panel
FieldWhat it does
KindNone, Horizontal, Vertical or Grid.
Padding, SpacingThe gap inside the edge and between children.
Child alignmentWhere the children sit when there is spare room.
Reverse orderLay them out from the other end.
Cell size, Constraint, Count(Grid) The size of each cell, and whether to fix the number of columns or rows.
Child controls size, Child force expandWhether the group sets each child's width and height, and whether children grow to fill the spare room.

A child that should not be arranged (a close button in a panel's corner, a badge on an icon) has Ignore layout in its Layout element group. The group leaves it where its own anchors put it. The same group sets a child's min, preferred and flexible size.

Sizing: Content size fitter, Layout element, Aspect ratio fitter​

Unity's three sizing components are groups on the UI card.

Content size fitter: Horizontal fit and Vertical fit. Preferred size makes that side as big as the content needs (a label as wide as its text); Min size as small as it can be (wrapped text as narrow as its longest word); Unconstrained uses the Rect Transform's size.

Layout element (on a child of a panel with a layout group):

FieldWhat it does
Ignore layoutThe group leaves it where its own anchors put it (a close button in a corner, a badge on an icon).
Min width / heightNever smaller than this.
Preferred width / heightThe size it asks for.
Flexible width / heightIts share of the room left over: 1 and 3 split it a quarter and three quarters.

Tick a field to use it. The group reads them on the sides where Child controls size is on.

Aspect ratio fitter: Aspect ratio is width Γ· height.

Aspect modeWhat it does
Width controls heightThe height follows the width.
Height controls widthThe width follows the height.
Fit in parentAs big as fits inside the parent, centred (a picture letterboxed on any screen).
Envelope parentCovers the whole parent, centred, the extra cut off (a background that fills every screen shape).

Scroll View​

A Scroll rect turns an element into a scrolling window, like Unity's Scroll Rect: the element is the viewport (whatever sticks out of it is cut off) and its first child is the content, which a drag or the mouse wheel moves. Use it for a long list, an item shop or a log.

Add β†’ UI β†’ Scroll View makes one ready to fill: the view, a Content panel inside it, and a Scrollbar Vertical linked to it. Put the rows or items inside Content. For a list that grows, give Content a Vertical or Grid layout group and set its Vertical fit to Preferred size.

By hand: give any panel a Scroll rect (Inspector β†’ Scroll rect β†’ Enabled) and put the content panel inside it as its first child.

FieldWhat it does
Horizontal, VerticalWhich directions it scrolls.
MovementElastic springs back from the edge, Clamped stops at it, Unrestricted goes anywhere.
ElasticityHow quickly it springs back (seconds).
Inertia, DecelerationKeep gliding after you let go, and how much speed is left after a second.
Wheel (px)How far one notch of the mouse wheel scrolls.
Horizontal scrollbar, Vertical scrollbarA Scrollbar that shows where the content is and moves it.
VisibilityPermanent, or Auto hide: the scrollbars are hidden while everything fits.

A drag that starts on a button inside still scrolls, and a tap still presses the button. If something under the finger has its own drag hooks (see Drag and drop), that thing takes the drag instead and the scroll view stays still.

A script can move the content too: it is an ordinary element, so content.setUIPosition(0, 120) scrolls it. Or set the scrollbar: bar.setUIValue(0) goes to the bottom of a vertical list.

Scrollbar​

A Scrollbar (Add β†’ UI β†’ Scrollbar) is a track with a handle, like Unity's. The handle's length shows how much of the content is in sight. Drag the handle to move it; a press on the track moves it one handle-length. With a controller, select it and push along the bar to move it by a tenth.

FieldWhat it does
DirectionWhich end the handle starts from. A vertical bar in a scroll view is Bottom to top: value 1 is the top of the list.
ValueWhere the handle is, 0 to 1.
SizeHow much of the track the handle covers, 0 to 1. A linked scroll view sets it.
Number of stepsStops the handle at that many places (0 = anywhere). 5 stops it at 0, 0.25, 0.5, 0.75 and 1.
Handle colorThe handle's color. The Selectable colors tint the handle.

Link it in the scroll view's Scroll rect (Vertical scrollbar or Horizontal scrollbar). Unlinked, it is a plain value the player sets. On value changed fires whenever it moves, also when the list is dragged; Bar.value reads it and Set slider value sets it.

Drag and drop and pointer events​

An element with Raycast target on and a code script can define these functions, named like Unity's EventSystem handlers. Each is called with an event: event.x, event.y (screen position), event.delta (how far the pointer moved, in the element's reference pixels with Y up, so you can add it to anchoredPosition as it is), and for a drop, event.dragged.

FunctionWhen
onPointerDown, onPointerUpA finger or mouse button goes down on the element, and comes up (a tap is a down and an up with no drag between).
onPointerEnter, onPointerExitThe mouse moves onto or off the element.
onLongPressHeld for half a second without moving.
onBeginDrag, onDrag, onEndDragThe pointer moved more than a few pixels while down on the element.
onDropSomething was dropped here: event.dragged is the element that was being dragged.
// On every inventory slot
const me = Number(entity.name.slice(4)); // "Slot3" β†’ 3
function onBeginDrag() { Bag.beginDrag(me); }
function onDrag(e) { Bag.dragBy(e.delta); }
function onEndDrag() { Bag.endDrag(); }
function onDrop(e) { Bag.move(Number(e.dragged.name.slice(4)), me); }

A drag is not a click, so a button that is dragged does not also press. game.uiAt(x, y) lists the elements under a screen point, topmost first. The Loot Room showcase is a backpack built on exactly this.

Lists that grow​

To add rows while the game runs, make the row a prefab and spawn it into the list:

const list = game.find('BookList');
for (const item of game.table('Item').all()) {
const row = game.spawn('BookRow', undefined, undefined, list); // the 4th argument is the parent
row.getChildren()[0].setText(item.title);
}

A UI element needs a Canvas above it to be drawn, which is why it is spawned inside a parent that has one. A layout group lays the new row out at once.

Masks and effects​

Mask & effects
Mask & effects
  • Mask: Rectangle cuts off whatever sticks out of the element (a scrolling list, a rounded avatar); Image shape cuts it to the shape of a picture.
  • Blend mode: how the element mixes with what is behind it: Normal, Additive, Multiply, Screen, Overlay and more. Use Additive for glows.
  • Effects: a stack you add to with + Add effect: Blur, Frosted glass, Brightness, Contrast, Saturation, Hue shift, Grayscale, Invert and Drop shadow.

The UI is drawn by the browser, so there are no shaders on UI elements and a blend mode mixes the UI only with other UI, not with the 3D scene behind it.

Screens and panels​

A Screen is a full-screen panel. Showing or hiding the screen shows or hides everything in it, so one action opens a whole menu.

A typical pause menu:

  1. Add a Screen named PauseScreen with a dark, half-transparent background; turn its Visible off.
  2. With PauseScreen selected, add a Text β€œPaused” and a Button ResumeButton.
  3. Add a Button PauseButton (outside the screen) anchored top-right.
  4. Events:
    • WHEN PauseButton: On clicked β†’ PauseScreen: Show, System: Pause game
    • WHEN ResumeButton: On clicked β†’ PauseScreen: Hide, System: Resume game

Screens that start hidden are still shown in the editor when you select them or something inside them.

  • A panel with a visible background blocks taps to the game behind it (unless Raycast target is off).
  • A button's taps never reach the joystick or On screen tapped.

UI in events and expressions​

  • Conditions: On clicked ⚑, Is held down, Is selected, On submitted ⚑, On typing finished ⚑, Is being typed in, Is on, Compare slider value, On value changed ⚑.
  • Actions: Show, Hide, Show / hide, Set label, Set position, Set size, Set anchors, Set pivot, Move to element, Put inside, Set slider value, Add to slider value, Set slider maximum / minimum, Enable / disable, Select, Set toggle, Set selected option, Add option, Clear options, Start typing, Set image, Set font, Set background color, Set text color, Set bar color.
    • Move to element puts the object's pivot on the middle of another element, plus an offset: a tooltip next to the slot you pressed, a marker on a map icon. It works from where both are drawn, so any anchors and scaling are fine.
    • Put inside moves an element into another (a slot into a panel, an item into a list). Attach to and Detach also work on UI elements.
  • Expressions: HealthBar.value, HealthBar.min, HealthBar.max, PlayButton.pressed, ScoreText.text.
  • On a UI element Panel.x and Panel.y are its offset from its anchors (what Set position sets, Y up) and Panel.width and Panel.height its size (what Set size sets). Copying one element's x and y onto another only lines them up when both have the same parent and anchors. To put an element where another one is drawn, use Set screen position with Other.screenX and Other.screenY, or Move to element.
  • Panel.screenX and Panel.screenY are where an element's pivot is drawn, in canvas pixels from the bottom-left corner. This is Unity's transform.position (the other one, x and y, is its anchoredPosition): it does not depend on the element's parent or anchors, so Icon.screenX + 40 is always 40 pixels to the right of the icon.
  • Panel.centerX and Panel.centerY are where the middle of its box is drawn. They differ from screenX and screenY when the element's pivot is not in the centre (a corner-anchored button often has its pivot in the corner). Move to element puts the moving element's pivot on the target's middle, so Set screen position to (Target.centerX, Target.centerY) does exactly the same.

See the UI conditions and UI actions.

UI in scripts​

entity.setText('HP'); // text, or a button's label
entity.setUIFont('Kenney Pixel'); // a font in Files, by name ('' = the default font)
entity.setUIValue(entity.getUIValue() - 10); // a slider's value
entity.setUIInteractable(false); // grey a button or slider out
entity.selectUI(); // the button a controller or the arrow keys are on
if (entity.isUISelected()) { /* show its tooltip */ }
entity.setToggleOn(!entity.isToggleOn()); // a Toggle (its group follows)
entity.setUIOptions(['Low', 'Medium', 'High']); // a Dropdown's options; setUIValue(1) picks one

// The layout is Unity's Rect Transform. Pixels are reference-resolution pixels, Y counts up.
const rect = entity.component('ui');
rect.anchorMin = [0, 1]; rect.anchorMax = [0, 1]; rect.pivot = [0, 1]; // top-left
rect.anchoredPosition = [16, -16];
rect.sizeDelta = [200, 40];
rect.rotation = 8; // degrees, counter-clockwise

entity.setUISize(200, 40); // width and height; leave one out to keep it
entity.setUIAnchors(0, 1, 0, 1); // min x, min y, max x, max y
entity.setUIPivot(0.5, 0.5);
entity.moveUITo(game.find('Slot3'), 0, -40); // pivot onto another element, plus an offset
const p = game.find('Icon').getUIScreenPosition(); // where it is drawn: canvas px from the bottom-left
entity.setUIScreenPosition(p.x + 40, p.y); // like Unity's transform.position
entity.attachTo(game.find('Panel')); // put it inside another element

See the scripting API for the rest.