UI Toolbox logoUI Toolbox
Support

LoadingScreen

A LoadingScreen covers the panel while a scene or another job loads. It has a title, a progress ring or bar, tips that fade in turn, background art and an optional "press any key" prompt. It fades in and out, blocks the pointer, the keys and the gamepad for the controls under it, and stays at least MinimumTime seconds, so a fast load does not flash. A screen with no setting shows "Loading" and a spinning ring.

A loading screen with the title Entering the mine, a progress ring and a tipA loading screen with the title Entering the mine, a progress ring and a tip

Sample: the Loading example scene enters and leaves a level behind a loading screen, with a ring or a bar and a "press any key" prompt. Its screen is a small scene of its own: art passes by behind the content, a mine cart rides the bar, the tips sit on a card, and crystals float up for the player to catch while the level loads.

How to add a loading screen in UXML:

  1. Declare the screen in the UXML of the document, next to the workspace. Set the title, the minimum time and the tips there.
  2. Find the screen in code and call LoadSceneAsync where your game changes the scene.
<tb:LoadingScreen
    name="loading"
    title="Entering the mine"
    minimum-time="2000"
    tips="Crystals glow near water.,Rest at a campfire to heal." />
var screen = root.Q<LoadingScreen>("loading");
root.Q<Button>("enter").clicked += async () =>
{
    var ok = await screen.LoadSceneAsync("Mine", LoadSceneMode.Additive);
    if (!ok) Debug.Log("The scene did not load");
};

LoadSceneAsync shows the screen, loads the scene, follows the progress, waits for the minimum time and the key, and hides the screen. The scene waits at 90% until the screen is ready, then it activates.

How to follow a load that you start yourself, such as a scene unload:

var operation = SceneManager.UnloadSceneAsync("Mine");
if (operation != null) await screen.LoadAsync(operation);

How to run a job of your own, such as an Addressables load or a save game read, which has no AsyncOperation:

screen.Show();
for (var i = 0; i < files.Count; i++)
{
    await Import(files[i]);
    screen.Progress = (i + 1f) / files.Count;
}
// waits for the minimum time and the key, then hides the screen
await screen.CompleteAsync();

How to make a loading screen in code:

var screen = new LoadingScreen
{
    Title = "Entering the mine",
    MinimumTime = 2000,
    PressAnyKey = true
};
screen.Tips = new List<string>
{
    "Crystals glow brighter near water.",
    "Rest at a campfire to heal your party."
};
// the anchor: the root of the document, or an element in it
await screen.LoadSceneAsync("Mine", LoadSceneMode.Additive, root);

The title and the tips are AnimatedLabels, so the effect tags work in them. A title that waves, and tips that type themselves in:

screen.Title = "<wave>Entering the mine</wave>";
screen.TypeTips = true; // type-tips="true" in UXML
Member Description
Title (title) The line above the progress. Empty (the default) shows the translated "Loading". Effect tags work in it, and in the tips.
Background (background) The art that fills the screen behind the content, scaled to fill and cropped. A dim layer over it keeps the text readable. None (the default) shows the plain background of the theme.
Tips (tips) The tips that fade in turn under the progress. In UXML a comma separated list, so a tip with a comma needs the property in code. Assign a new list to change the tips. Empty (the default) shows no tip.
TipDuration (tip-duration) The milliseconds that each tip shows. 4000 by default, at least 500.
TypeTips (type-tips) Each tip types itself in, as a TypewriterLabel, each time it shows. Off by default: the tips fade in whole. Give a long tip enough TipDuration to type.
Indicator (indicator) Ring (the default), a ProgressRing, or Bar, a progress bar.
SpinnerAnimation (spinner-animation), SpinnerAnimationClip (spinner-animation-clip) A SpriteSheet that plays in place of the indicator while the length is not known, such as an hourglass or a running hero, and the clip that loops. A known progress shows the ring or the bar. It plays only while the screen shows. None (the default) spins the ring or runs the bar. SpinnerAnimationElement is its AnimatedImage.
Progress (progress) The progress from 0 to 1. A negative value (the default) means that the length is not known: the ring spins and the bar runs. LoadSceneAsync and LoadAsync set it.
MinimumTime (minimum-time) The milliseconds that the screen stays at least, counted from the show. 1000 by default. 0 hides the screen as soon as the job ends.
PressAnyKey (press-any-key) After the job ends, the screen shows the prompt and waits for a key, a pointer press, or the submit or cancel button of a gamepad before it hides. Off by default.
PromptGlyph (prompt-glyph) The glyph of the prompt, as in InputGlyph. keyboard-key, the empty key cap, by default; gamepad-a for a gamepad.
Show(anchor) Fades the screen in over the workspace of anchor, or over its panel, and takes the focus. A screen in the hierarchy needs no anchor.
Hide() Fades the screen out. A load that is still running goes on, and its task ends with false.
LoadSceneAsync(name, mode, anchor) Shows the screen, loads the scene and hides the screen at the end. The task is true at the end, and false when the scene is not in the build, a load is running, or something hides the screen first. name is the name or the path in the build settings.
LoadAsync(operation, anchor) The same for an AsyncOperation that you started. It does not hold the operation, so the scene of a load may activate before the screen hides. It throws when the operation is null.
CompleteAsync() Ends a job that you started with Show: sets the progress to 1, waits for the minimum time and the key, and hides the screen. The task is false when the screen is not shown.
IsOpen, IsLoading, IsWaitingForKey The screen shows. A load or a job runs. The prompt shows.
Opened, Closed The events. Closed is raised when the hide starts, before the fade out ends, and also when something removes the screen from the panel.
TipView, Ring, Bar The FlipView of the tips, the ring and the bar, to read or to restyle.

Tips:

Styling

Class Element
tb-loading-screen The screen. It fills the workspace or the document, centers the content and uses --tb-color-background.
tb-loading-screen--hidden Opacity 0: the start of the enter animation and the end of the exit.
tb-loading-screen--anim-in, --anim-out The transitions of opacity, with --tb-animation-duration-normal and the entrance or exit easing.
tb-loading-screen--waiting While the screen waits for a key. It shows the prompt.
tb-loading-screen__background The art of Background, with -unity-background-scale-mode: scale-and-crop. Hidden while Background is empty.
tb-loading-screen__scrim A layer of --tb-color-overlay over the art. Hidden while Background is empty.
tb-loading-screen__content The column with the title, the indicator, the tips and the prompt. At most 90% wide.
tb-loading-screen__title The title: 28 px, bold.
tb-loading-screen__ring The ProgressRing, 120 x 120 px. The arc takes the color.
tb-loading-screen__bar The progress bar, 360 px wide, and not wider than the content.
tb-loading-screen__tips The FlipView of the tips, 480 x 48 px.
tb-loading-screen__tip A tip: italic, centered, in --tb-color-text-muted.
tb-loading-screen__prompt The row with the glyph and the text. It has display: none until the screen waits for a key.
tb-loading-screen__prompt-glyph, __prompt-text The InputGlyph (24 px, --tb-color-accent) and the text.
tb-modal Also on the screen, while it shows.

To make the title larger, give the tips more room and fade slowly:

.tb-loading-screen__title { font-size: 40px; }
.tb-loading-screen__tips { height: 72px; }
.tb-loading-screen--anim-in,
.tb-loading-screen--anim-out {
    transition-duration: 600ms;
}

The LoadingScreenDemo scene shows a quick load, a screen between levels with tips, a ring and art of the next place behind it, a world build with a bar that names each stage while a hero walks along it, and a story chapter on parchment whose lore types itself in and that waits for a key.

For art behind the content, add an element to the screen and call PlaceBehind with the element of the CONTENT_CLASS class. With no Background, the screen shows no scrim, so the art shows at full strength. The LoadingBackdrop and LoadingRunner classes of the Loading example do this: a sky with layers that pass by, and an AnimatedImage that rides along the bar to the progress.

SVG: Background is a Background value. An SVG imported as a VectorImage works as well as a texture. See Pictures: PNG or SVG.