Build a screen in UI Builder
This page makes a settings screen in UI Builder, shows it in a scene, and reads its values from code. Then it puts the screen in a window.
Video tutorial: Settings screen. All videos: Video tutorials.
1. Make a UXML file
- In the Project window, right-click a folder, then click Create > UI Toolkit > UI Document.
- Name the file
SettingsScreen.uxml. - Double-click the file. UI Builder opens it.
2. Set up the canvas
- In the Hierarchy of UI Builder, select the top item,
SettingsScreen.uxml. - In the Inspector, under Canvas Size, select Match Game View. The canvas then has the size of the Game view.
- In the toolbar of the Viewport, set the theme to UI Toolbox Dark. The theme menu also lists the other UI Toolbox themes, such as UI Toolbox Light and UI Toolbox Game; the canvas then shows the colors of that theme.
The Toolbox controls add their style sheets when they show, also in UI Builder. You do not add style sheets by hand. In UI Builder the canvas theme menu sets the theme of the document.
3. Find the controls
- In the Library, click the Project tab.
- Open Custom Controls (C#) > UI Toolbox.
The controls are in the same groups as in these documents: Inputs, Display, Overlays, Navigation, Data and charts, Layout, Settings, Windows and Workspace. Some controls are parts of another control, such as PieSlice in a PieChart or SidebarItem in a Sidebar. Put a part in its control.
4. Add controls and set their attributes
- Drag a Card from Display onto the canvas.
- In the Inspector, set Title to
Audioand Description toSound and music. - Drag a Switch from Inputs into the card. Set Name to
musicand Label toMusic. - Drag a Rating from Inputs into the card. Set Name to
difficulty, Label toDifficultyand Max to5.
Each attribute in the Inspector is a UXML attribute. The page of each control lists its attributes.
5. Save
Press Ctrl+S (Cmd+S on macOS). UI Builder writes the UXML file. The file is plain text, so you can also edit it in a code editor:
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:tb="UIToolbox">
<tb:Card title="Audio" description="Sound and music">
<tb:Switch name="music" label="Music" />
<tb:Rating name="difficulty" label="Difficulty" max-value="5" />
</tb:Card>
</ui:UXML>
6. Show the screen in a scene
- In the Hierarchy of the scene, right-click, then click UI Toolkit > UI Document.
- Select the new GameObject. In the Inspector, give the
UIDocumenta Panel Settings asset. - Drag
SettingsScreen.uxmlinto the Source Asset field of theUIDocument. - Press Play.
7. Read the values from code
Find a control by its name with Q<T>. Add this component to the GameObject that has the UIDocument:
using UIToolbox;
using UnityEngine;
using UnityEngine.UIElements;
public class SettingsScreen : MonoBehaviour
{
private void OnEnable()
{
var root = GetComponent<UIDocument>().rootVisualElement;
var music = root.Q<Switch>("music");
music.RegisterValueChangedCallback(evt =>
Debug.Log($"Music: {evt.newValue}"));
var difficulty = root.Q<Rating>("difficulty");
difficulty.RegisterValueChangedCallback(evt =>
Debug.Log($"Difficulty: {evt.newValue}"));
}
}
8. Put the screen in a window
- Open
SettingsScreen.uxmlin UI Builder. - From Windows, drag a Workspace onto the canvas. In the Inspector, under Flex, set Grow to
1, so the workspace fills the screen. On the canvas, the workspace shows a dashed outline and the name "Workspace". UI Builder does not save or restore the window session of the workspace. - Drag a Window into the workspace. Set Id to
Settings, Title toSettings, Width to360, Height to240and Initial Window State toopen. The canvas shows the window with its title bar, at its initial position and size. - Drag the card into the window, on the canvas or in the Hierarchy of UI Builder.
- Save and press Play. Drag the window by its title bar, and resize it by an edge.
To open and close the window from a button, add a WorkspaceToolbar in the workspace and a WorkspaceToolbarButton in the toolbar. Set the Window Id of the button to Settings and its Title to Settings; the button shows the title as its text. The toolbar shows a dashed outline and its name on the canvas, and the window moves down below the toolbar. See Toolbar buttons. For all window attributes, see Create windows.
Editors for text attributes
Some attributes are text with a format, or a list of short entries. The Inspector of UI Builder, and the Inspector of a component, shows an editor for them. Most editors are toolbox controls in the colors of the editor skin. A text that the editor does not know stays as it is, with a warning.
| Attribute | Editor | Controls |
|---|---|---|
| Number format | A ComboBox: type a format, or pick a common one; its list shows a sample of each. Two sample numbers in the format, and a warning for a text that is not a number format. |
Gauge (format-string, tick-format), Graph (x-format, y-format, y2-format), PieChart, SpiderChart, HeatMap, Treemap and SankeyChart (format-string), StatDelta (format-string), Timeline (time-format), NumericUpDown, Knob, RangeSlider and XYPad (format-string) |
| Areas | The cells of the grid. Type an area name in Paint and drag over the cells. + Row, − Row, + Column and − Column change the size. The name . erases. |
GridPanel (areas) |
| Shortcut | Record: press the keys, such as Ctrl+Shift+S. Escape stops. A warning for a text that is not a shortcut. | CommandPalette (shortcut), Sidebar (shortcut), MenuItem (shortcut), Kbd (keys) |
| Date | A DatePicker: type an ISO date such as 2026-09-24, or pick one in the calendar, which has a Today button. Clear the text to clear the date. The date in words, and a warning for a text that is not an ISO date. |
DatePicker and MonthCalendar (date, min-date, max-date), DatePicker (range-end), WeekSchedule (date) |
| Glyph | A ComboBox: its list shows each glyph beside its name, in groups such as keyboard and xbox, and typed text filters it. A preview of the glyph. |
InputGlyph (glyph), GamepadGlyph, InteractionPrompt and PromptBar, AbilitySlot and DialogueBox (keyboard-glyph), LoadingScreen (prompt-glyph) |
| Theme | A ComboBox with the themes in Resources/UIToolbox/Themes in its list, and a warning for a name that is not one of them. |
Workspace (theme-name) |
| List of entries | A TagField: each entry is a chip. Type an entry and press Enter, or type a comma, to add it. The × of a chip removes it. An entry cannot hold a comma. |
AutoCompleteField, ChoiceMenu, ComboBox, OptionSelector, SearchDropdown and SplitButton (choices), Breadcrumb (items), CompassBar (labels), TagField (suggestions, tags) |
| Date format | A ComboBox: type a format, or pick a common one; its list shows today in each. Today in the format, and a warning for a text that is not a date format. |
DatePicker (date-format) |
| Comma list | A TagField like the list of entries, for a text that holds the entries with commas: each entry is a chip, and the text keeps its commas for the UXML. |
Graph (values, categories), Sparkline (values), HeatMap (row-labels, column-labels), DataGridColumn (choices), UnlockNode (requires) |
| Cell format | A ComboBox with common number and date formats, such as F1 or yyyy-MM-dd. |
DataGridColumn (format-string) |
| Range Bands | A list: + adds a band with From, To and Color. | Gauge |
Put the same attributes on a string field of your own component to get the same editor: [NumberFormat], [GridAreas], [Shortcut], [IsoDate], [DateFormat], [CellFormat], [CommaList], [GlyphName] and [ThemeName]. Put [TagList] on a List<string> field. All of them are in the UIToolbox namespace.
What shows only in Play mode
UI Builder shows the layout and the styles. Some things happen only in Play mode:
- The workspace opens the windows that are not
closed, and the windows move, resize, dock and animate. UI Builder draws each Window and WindowTemplateElement at its initial position and size, whatever its initial state, and each DockZone at its edge. - Overlays such as Dialog, Drawer and MessageBox stay hidden until your code shows them. UI Builder shows them in place, so you can edit their content. To hide one while you edit the screen around it, set its Display to None in the Inspector; the overlay still shows when your code opens it. See Custom overlays (OverlayElement).
- Tooltips, keyboard shortcuts and gamepad input work.
- Controls that get their data from code, such as DataGrid, Graph and ChatView, show only that data. On the canvas an empty one shows faint sample content in a dashed outline, so you see its look and its size. The outline says what gives the control its content, such as "Sample: set Items". The sample steps aside when you set the content, and UI Builder does not save it to the UXML file.
- Layers and overlays that show nothing until the game fills them, such as ParticleLayer, FloatingTextLayer and WorldMarkerLayer, show a dashed outline with their name on the canvas. A control that would have no size there gets a small one.
- The rolls, countdowns and ticks wait for Play mode: Credits shows its first page still, an AutoClickButton does not count down, and a FileBrowser shows sample folders in place of the disk.
- The samples, the outlines and the overlay previews show on the UI Builder canvas only. In another editor window, such as an Inspector, a control shows as in Play mode.
Next steps
- Make the scene objects and files with a wizard: Setup Wizard.
- See each control in use: Example scenes.
- Change colors, sizes and fonts: Theme variables.