UI Toolbox logoUI Toolbox
Support

Notifications (NotificationArea)

A NotificationArea fills its parent and stacks toast bubbles in one corner.

Three toasts in a NotificationArea: info, success and warning, each with a close button and a bar of the time leftThree toasts in a NotificationArea: info, success and warning, each with a close button and a bar of the time left

Video tutorial: Notifications. All videos: Video tutorials.

Each workspace has one, created on first use:

workspace.Notifications.Show("Layout saved", Severity.Success);

var bubble =
    workspace.Notifications.Show("Connection lost", Severity.Error,
        durationMs: 0);
bubble.Title = "Network";
bubble.AddAction("Retry", Reconnect);
bubble.Clicked += _ => OpenLog();

Outside a workspace, add an area yourself:

<UIToolbox.NotificationArea
    name="toasts"
    corner="BottomRight"
    max-visible="3"
    stack-duplicates="true" />

In the UI Builder, the area shows a dashed outline with its name, so you can find it. The outline does not show in Play mode or in a build.

Member Description
NotificationArea.Show(message, severity, durationMs) Adds a bubble and returns it. The message is rich text.
NotificationArea.Show(bubble) Adds a bubble that you built.
NotificationArea.ShowBanner(title, message, severity, durationMs) Adds a Banner bubble (a big title over a smaller line, 2500 ms) and returns it. See "Show a banner" below.
NotificationArea.ShowTask(task, loading, success, error) Adds a loading bubble for a Task and returns it. See "Show a task" below.
NotificationArea.Corner (corner) TopRight (default), TopLeft, BottomRight, BottomLeft, TopCenter, BottomCenter or Center (the middle of the parent, for banners).
NotificationArea.MaxVisible (max-visible) Most bubbles at once (5). Above it a new bubble waits in the queue.
NotificationArea.Queue (queue) Keeps the bubbles above MaxVisible in a queue (true). A waiting bubble shows when a shown bubble leaves, and its timer starts then. false dismisses the oldest bubbles to make room.
NotificationArea.StackDuplicates (stack-duplicates) Shows equal messages as one bubble with a count (false). Show adds to Count of a bubble with the same message, title and severity, starts its countdown again and returns that bubble.
NotificationArea.ShowProgress (show-progress) Shows the countdown bar on each bubble (true).
NotificationArea.SlideBubbles (slide-bubbles) The bubbles slide to their new places when a bubble comes, goes or changes its height (true). false makes them jump.
NotificationArea.EnterAnimation (enter-animation), ExitAnimation (exit-animation) How bubbles come in and go out: Preset (default, the look of the Preset of the bubble), SlideFromEdge, Fade, Zoom or Rise. See "Change how bubbles come in and go out" below.
NotificationArea.EnterEasing (enter-easing), ExitEasing (exit-easing) A USS easing name (NotificationEasing): Default (the easing of the theme), Linear, Ease, EaseInOutBack and so on.
NotificationArea.EnterDurationMs (enter-duration), ExitDurationMs (exit-duration) Milliseconds of the enter or the exit. 0 (default) keeps the time of the preset.
NotificationArea.EnterCurve (enter-curve), ExitCurve (exit-curve) An AnimationCurve from 0 to 1 that drives the enter or the exit instead of the USS transition. A curve that passes 1 overshoots. null (default) uses the USS transition.
NotificationArea.QueuedCount The bubbles that wait in the queue.
NotificationArea.DismissAll() Dismisses every bubble, also the bubbles in the queue.
NotificationBubble.Title (title) A bold line above the message. Empty (default) shows no line.
NotificationBubble.Description (description) The message (rich text).
NotificationBubble.Icon An image before the text, as a Background (a texture, a sprite or a vector image). null (default) shows no image.
NotificationBubble.IconAnimation (icon-animation), IconAnimationClip (icon-animation-clip) A SpriteSheet that plays in the icon while the bubble shows, such as a coin that spins for a pickup, and the clip that plays. It covers Icon. None (the default) keeps the still icon.
NotificationBubble.Severity (severity) Info (default), Success, Warning or Error.
NotificationBubble.Preset (preset) The look and the entrance: Toast (default), Banner, Achievement or KillFeed. See "Show a banner" and "Show an achievement or a kill feed" below.
NotificationBubble.EnterAnimation, ExitAnimation, EnterEasing, ExitEasing, EnterDurationMs, ExitDurationMs, EnterCurve, ExitCurve The same members as the area, to override it for one bubble. Inherit (animation), Default (easing), 0 (duration) and an empty curve (default) take the value of the area.
NotificationBubble.DurationMs (duration) Milliseconds of game time before the bubble dismisses itself (5000). The countdown stops while Time.timeScale is 0. 0 or less keeps it until the user closes it.
NotificationBubble.RemainingMs Milliseconds until the bubble dismisses itself.
NotificationBubble.Loading (loading) Shows a spinner before the text (false). A loading bubble does not dismiss itself.
NotificationBubble.Count The number of equal messages that the bubble stands for (1). Above 1 the bubble shows it as "x3".
NotificationBubble.ShowProgress Shows the countdown bar on this bubble. null (default) uses ShowProgress of the area.
NotificationBubble.Closable (closable) Shows the close button (true).
NotificationBubble.AddAction(text, callback) Adds a button. A click runs the callback, then dismisses the bubble.
NotificationBubble.Detail (detail) More text under the message (rich text). It shows while the pointer is on the bubble. A bubble with a detail shows "..." under the message until then.
NotificationBubble.Expanded Shows the detail from code. The pointer sets it on enter and clears it on leave.
NotificationBubble.Dismiss() Plays the exit animation, then removes the bubble.
NotificationBubble.Clicked Raised on a click outside the buttons, and on Submit when the bubble has the focus.
NotificationBubble.Dismissed Raised after the bubble leaves the hierarchy.

Update a shown bubble

Keep the bubble that Show returns and set its properties. The bubble changes in place and its countdown starts again.

var bubble = workspace.Notifications.Show("3 files left");
// Later
bubble.Description = "2 files left";
bubble.Severity = Severity.Warning;

Show a task

ShowTask shows a loading bubble while a task runs. When the task ends, the same bubble changes to a success or to an error, and then dismisses itself.

workspace.Notifications.ShowTask(SaveAsync(), "Saving...", "Saved",
    "Cannot save");

// The success message from the result of the task
workspace.Notifications.ShowTask(LoadAsync(), "Loading...",
    (int count) => $"{count} items loaded", "Cannot load");

To control the bubble yourself, set Loading and clear it when the work ends:

var bubble =
    workspace.Notifications.Show(
        new NotificationBubble { Description = "Connecting...",
            Loading = true });
// Later
bubble.Description = "Connected";
bubble.Severity = Severity.Success;
bubble.Loading = false;

Open a window on click

Clicked is raised on a click on the bubble, not on its close button or its action buttons. OpenWindow opens the window, or focuses it when it is open.

var bubble = workspace.Notifications.Show("New message: click to open");
// Keyboard and gamepad users can move to the bubble and press Submit
bubble.focusable = true;
bubble.Clicked += clicked =>
{
    workspace.OpenWindow("chat");
    clicked.Dismiss();
};

Show a pickup in a game

Give each pickup an icon and a count. With stack-duplicates, a pickup with the same message adds its count to the bubble that shows, so ten pickups of wood show as one "Wood x10" line.

<tb:NotificationArea
    name="feed"
    corner="BottomLeft"
    stack-duplicates="true"
    show-progress="false"
    queue="false" />
feed.Show(new NotificationBubble
{
    Description = "Wood",
    Count = amount,
    Icon = Background.FromTexture2D(woodIcon),
    Severity = Severity.Success,
    DurationMs = 2500,
    Closable = false,
});

Show a banner

A banner is a big message in the middle of the screen, such as "Wave 3" or "Quest complete". Use an area with corner="Center" and max-visible="1", so the banners come one after the other.

<tb:NotificationArea name="banners" corner="Center" max-visible="1" />
var banners = root.Q<NotificationArea>("banners");
banners.ShowBanner("WAVE 3", "Hold the gate", Severity.Warning);
// waits until "WAVE 3" leaves
banners.ShowBanner("QUEST COMPLETE", "The lost caravan");

Show an achievement or a kill feed

Preset gives a bubble the look and the entrance of a game message. Set it on any bubble.

// Achievement: a gold edge, a larger icon, and the card rises into place
workspace.Notifications.Show(new NotificationBubble
{
    Preset = NotificationPreset.Achievement,
    Title = "ACHIEVEMENT",
    Description = "Pathfinder: find 10 hidden places.",
    Icon = Background.FromTexture2D(trophyIcon),
    DurationMs = 6000,
});

// Kill feed: one small line with no close button, from the right edge
killFeed.Show(new NotificationBubble
{
    Preset = NotificationPreset.KillFeed,
    Description = "<b>Mira</b>  [Bow]  Raider",
    DurationMs = 3000,
});

Change how bubbles come in and go out

Set the enter and the exit on the area, or on one bubble. The enter and the exit are set apart. When nothing is set, each preset (Toast, Banner, Achievement, KillFeed) keeps its own look.

var area = workspace.Notifications;
area.EnterAnimation = NotificationAnimation.SlideFromEdge;
area.EnterEasing = NotificationEasing.EaseOutBack;
area.EnterDurationMs = 350;
area.ExitAnimation = NotificationAnimation.Fade;

// A curve drives one bubble instead of the easing
var bubble = new NotificationBubble
{
    Description = "Quest complete",
    EnterAnimation = NotificationAnimation.Zoom,
    EnterCurve = NotificationCurves.Overshoot(),
};
area.Show(bubble);

Tips

Styling

The rules are in Assets/UIToolbox/Runtime/Resources/UIToolbox/Styles/Controls.uss.

Class Element
tb-notification-area The overlay. Modifiers: --top-right, --top-left, --bottom-right, --bottom-left, --top-center, --bottom-center, --center.
tb-notification One bubble. Modifiers: --info, --success, --warning, --error.
tb-notification--banner, tb-notification--achievement, tb-notification--killfeed The Preset classes. A banner is wide and centered, with a frame in the severity color, and it scales in. An achievement has a gold edge and rises into place. A kill feed line is small, has no close button and slides in from the right. A theme can restyle them.
tb-notification__body, __title, __message, __actions, __action, __close Parts of a bubble.
tb-notification__detail, tb-notification__more The detail text (muted, small, hidden) and the "..." mark.
tb-notification__icon The image of Icon (32 x 32 pixels).
tb-notification__count The count of equal messages, as "x3". It is a Badge, so it also has tb-badge; the tb-notification__count rule keeps the look of the bubble.
tb-notification__spinner The spinner of a loading bubble (a ProgressRing).
tb-notification__progress The countdown bar.
tb-notification--loading State class: the bubble shows the spinner.
tb-notification--expanded State class: shows the detail and hides the mark.
tb-notification--hidden State class: where the enter animation starts and the exit animation ends.
tb-notification--anim-in, tb-notification--anim-out Transition classes for the enter and exit animations.
tb-notification--motion, tb-notification--motion-slide, --motion-fade, --motion-zoom, --motion-rise State classes while an enter or exit style plays. With tb-notification--hidden, they set where the enter starts and the exit ends.
tb-notification--slide Transition class: the bubble slides to its new place when a bubble before it comes, goes or changes its height.