UI Toolbox logoUI Toolbox
Support

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

  1. In the Project window, right-click a folder, then click Create > UI Toolkit > UI Document.
  2. Name the file SettingsScreen.uxml.
  3. Double-click the file. UI Builder opens it.

2. Set up the canvas

  1. In the Hierarchy of UI Builder, select the top item, SettingsScreen.uxml.
  2. In the Inspector, under Canvas Size, select Match Game View. The canvas then has the size of the Game view.
  3. 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

  1. In the Library, click the Project tab.
  2. 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

  1. Drag a Card from Display onto the canvas.
  2. In the Inspector, set Title to Audio and Description to Sound and music.
  3. Drag a Switch from Inputs into the card. Set Name to music and Label to Music.
  4. Drag a Rating from Inputs into the card. Set Name to difficulty, Label to Difficulty and Max to 5.

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

  1. In the Hierarchy of the scene, right-click, then click UI Toolkit > UI Document.
  2. Select the new GameObject. In the Inspector, give the UIDocument a Panel Settings asset.
  3. Drag SettingsScreen.uxml into the Source Asset field of the UIDocument.
  4. 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

  1. Open SettingsScreen.uxml in UI Builder.
  2. 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.
  3. Drag a Window into the workspace. Set Id to Settings, Title to Settings, Width to 360, Height to 240 and Initial Window State to open. The canvas shows the window with its title bar, at its initial position and size.
  4. Drag the card into the window, on the canvas or in the Hierarchy of UI Builder.
  5. 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:

Next steps