Home › Systems › AFS_UI_Notifications
System

AFS_UI_Notifications

Transient notifications shown in a stacking container, with a default styled variant and a one-call library.

What it gives you

  • Fire-and-forget notifications from anywhere
  • Automatic stacking and expiry
  • Themed styling with icon, colour and sound

Requires

AFA_Colors AFL_Libraries AFS_UI

Required by

AFS_UI_Menu AF_Examples

6 assets20 API members

Description

Notifications are the framework's answer to "tell the player something happened without interrupting them". BFL_Notifications.Notification_ShowDefaultNotification takes a pawn, an icon, text, a colour, a duration and a sound, and handles everything else — creating the notification object, placing it in the container, stacking it with any others and removing it when it expires.

Because it resolves the container through the pawn, the same call works in VR where notifications appear in spatial UI, and on desktop where they appear on the HUD.

Setup

  1. Confirm the pawn has the spatial UI or HUD ability the container needs.
  2. Call the library function from anywhere with a pawn reference.

Usage

Showing a notification

Call Notification_ShowDefaultNotification with the pawn, an icon texture, the text, a PDA_Color and a duration. Six seconds is the default and works for most messages.

Custom notifications

Derive from BP_Notification and WBP_Notification for a different layout, then spawn it through SpawnInsideNotificationContainer.

Three notifications stacked in the corner
AFS_UI_Notifications_result.pngThree notifications stacked in the corner
Three notifications stacked in the corner

Key properties

PropertyWhen to change
DurationTime on screen; raise for longer messages
ColorUse the colour data assets so notifications match the theme

Extending

Derive from BP_Notification and WBP_Notification together — the object holds the data, the widget draws it.

Example map

Map_Examples_Notifications shows several notification types.

Troubleshooting

Nothing appears. The pawn lacks the UI ability that hosts the notification container.

API reference

Every blueprint asset in this module. Expand an asset to see its members.

Blueprints

BP_Notification5 members
extends Object

Object describing one notification: which pawn sees it, the widget class that draws it, how long it lasts and the sound it plays. Spawn Inside Notification Container adds the container to the pawn's HUD ability and hands itself over to be built into a widget. Subclass it when a notification needs content of its own, as the default one does; it is created in code rather than placed.

KindNameSignatureDescription
varPawnInfoPawnOwning pawn whose HUD this notification is shown on, normally set as the object is created. The notification container is added to that pawn's HUD component, so nothing appears when the pawn is empty or has no such component.
varWidget ClassInfoclass<WBP_Notification>Widget design the container creates for this notification, which is the default notification widget on the shipped subclass. Not exposed on spawn, so set it on the notification object before calling Spawn Inside Notification Container if you have written a design of your own.
varDurationInfofloatHow long the notification is meant to stay on screen, in seconds: six when spawned through Show Default Notification, ten by default on the notification object itself. Neither the container nor the widget reads it, so a notification stays up until Despawn Notification is called for it.
varSoundSoundSoundBaseCue carried with the notification for its appearance. Leave it empty and Spawn Inside Notification Container writes the shipped notification cue in, rather than passing the widget an unset sound.
fnSpawn Inside Notification Container(out Witget: WBP_Notification)Puts this notification on screen and returns the widget created for it. Falls back to the shipped notification cue when no sound is set, adds the notification container to the pawn's HUD at Z-order 10 unless it is already open, then asks that container to spawn the widget. Does nothing at all when the pawn has no HUD component.
BP_Notification_Default3 members
extends BP_Notification

Ready-made notification carrying an icon, a line of text and a colour data asset, paired with the default notification widget and a ten second duration. Created for you by Show Default Notification, so reach for the library first and copy this class only when you want a notification with different content.

KindNameSignatureDescription
varIconContentTexture2DTexture the default notification design shows in its icon image, applied when Update Icon is called on the widget with it. The image collapses while no texture is set.
varTextContenttextMessage the default notification design displays, applied when Update Body is called on the widget with it. The text block collapses while the message is empty.
varColorStylePDA_ColorColour asset the default notification design outlines itself with, applied when Update Colour is called on the widget with it. Leave it empty and the outline falls back to the theme's background colour.

Libraries

BFL_Notifications1 members
extends BlueprintFunctionLibrary

Function library reducing the notification flow to one static call. Show Default Notification builds a default notification for a pawn from an icon, a line of text, a colour and a duration, shows it and returns the widget. Call this rather than creating the notification object yourself.

KindNameSignatureDescription
fnNotification_ShowDefaultNotificationNotifications(Pawn: Pawn, Icon: Texture2D, Text: text, Color: PDA_Color, Duration: float, Sound: SoundBase, __WorldContext: Object, out Witget: WBP_Notification)Builds a default notification from the icon, text, colour, duration and sound given, puts it on the pawn's HUD and returns the widget created for it. The pawn needs a HUD component; without one nothing is shown and the widget comes back empty. Duration is six seconds on this pin, where the notification object's own default is ten.

Widgets

WBP_Notification4 members
extends WBP_Base

Root class for every notification widget: a named slot for the content, the slide-and-fade in and out animations, and Despawn Notification, which plays the fade, tells the container it has gone and removes itself. Inherit from this for a notification look of your own and point a notification object's Widget Class at it.

KindNameSignatureDescription
varNotificationContentBP_NotificationThe notification object this widget was spawned for, handed over by the container as it creates the widget. The container matches on it to find the right widget when Despawn Notification is called with an object, and a design of your own takes its content from here.
fnWidgetElement_getNamedSlotsSlots(out Slots: NamedSlot[])Returns the single notification slot inside the fixed 1200-unit-wide size box, so that whatever a notification design places there is initiated and themed with the rest of the tree.
eventDespawnNotification()Fades the notification out and removes it from the screen. Its Z-order drops to zero first, so it passes behind the notifications still standing, and On Despawn is broadcast once the animation finishes, which is what takes it out of the container's list.
eventWidgetElement_PostInitiateStyle()Called once the whole widget tree has been initiated and themed. Empty on the notification base, which is where a design of your own reads the Notification object and fills itself in.
WBP_Notification_Default4 members
extends WBP_Notification

The shipped notification look, an icon beside a line of text behind a rounded outline whose colour comes from the colour data asset on the notification. Paired with the default notification; copy it when you want a different arrangement of the same parts.

KindNameSignatureDescription
eventUpdateColor(SideColor: PDA_Color)Recolours the rounded outline around the notification, wrapping the colour asset given as a custom colour at high intensity. Pass nothing and the outline reverts to the theme's background colour at that same intensity.
eventUpdateBody(Text: text)Replaces the notification's message text, which collapses when the text is empty. Call it once the widget exists, since the text held on the notification object is not read for you.
eventUpdateIcon(Icon: Texture2D)Replaces the texture in the notification's icon, which collapses when no texture is passed. Call it once the widget exists; the icon held on the notification object is not read for you.
eventWidgetElement_PostInitiateStyle()Called once the whole widget tree has been initiated and themed. Left empty here, so the icon, message and outline colour stay as the designer left them until Update Icon, Update Body and Update Colour are called.

Widgets/Container

WBP_NotificationContainer3 members
extends WBP_Base

Stack that holds the notifications currently on screen. It builds each widget from a notification object, keeps the pile interpolating upwards as sizes change, and closes itself once the last one has despawned. Added to the pawn's HUD by the notification itself, so it is not a widget to add by hand.

KindNameSignatureDescription
fnDespawnNotificationNotifications(Notification: BP_Notification)Fades out every widget in this container showing the given notification object, by calling Despawn Notification on each of them. Passing an object the container is not showing does nothing.
fnSpawnNotificationNotifications(Notification: BP_Notification, out Widget: WBP_Notification)Creates the widget named by the notification's Widget Class, subscribes to its On Despawn and adds it to the canvas, auto-sized and anchored to the bottom centre directly above the notifications already showing, so the stack grows upwards. Called for you by Spawn Inside Notification Container.
eventDespawnMessage_Event(Notification: WBP_Notification)Internal handler bound to each notification widget's On Despawn delegate. Takes that widget out of the list and closes the container itself once the last notification has gone.