Spawning Dynamic Text Widgets on the Player UI with Verse
What you'll learn
- How to subscribe to a button device's
InteractedWithEventand receive the interactingagent - How to cast an
agentto aplayerand reach their UI with the fallibleGetPlayerUI[] - How to build a
text_block, place it inside acanvasslot, and add it to theplayer_ui - How to drive live text updates from a
<suspends>background loop usingSleepandGetRandomFloat
How it works
A custom UI in UEFN belongs to a single player, so we must start from something player-specific. We subscribe to a button_device's InteractedWithEvent, which sends the agent that pressed it. Because agents can be NPCs, we cast to player with player[Agent] inside an if — this is a fallible expression, so it uses [] brackets in a failure context. GetPlayerUI[...] is likewise fallible (it's <decides> and returns a player_ui, failing when the agent has no UI), so we bind it in the same if.
Once we hold a player_ui, we create a text_block widget, wrap it in a canvas (which lets us position widgets in slots), and call PlayerUI.AddWidget(...). A separate <suspends> coroutine, launched from OnBegin, simulates a live data feed with GetRandomFloat and prints each value — the same place you'd later push into a stored widget's text. Everything downstream of OnBegin runs in a suspendable context so Sleep is legal.
Let's build it
using { /UnrealEngine.com/Temporary/UI }
using { /Fortnite.com/Devices }
using { /Verse.org/Simulation }
using { /Verse.org/Random }
using { /Fortnite.com/UI }
# A custom device that adds a live text widget to a player's UI on button press.
floating_text_device := class<concrete>(creative_device):
# Drag a Button device here in the Details panel.
@editable
InteractButton : button_device = button_device{}
# The message shown in the spawned widget. `message` (localizable text) is what widgets display.
Message<localizes> : message = "Floating Text!"
# Entry point. Runs when the game starts.
OnBegin<override>()<suspends> : void =
# Fire our handler each time an agent interacts with the button.
InteractButton.InteractedWithEvent.Subscribe(HandleInteraction)
# Kick off a background loop simulating a live data stream.
DynamicUpdates()
# A custom UI belongs to one player, so cast the agent and resolve their UI.
HandleInteraction(Source : agent) : void =
# player[Agent] and GetPlayerUI[...] are both fallible — bind them in the if condition.
if (InPlayer := player[Source], PlayerUI := GetPlayerUI[InPlayer]):
# Build the text widget from our localized message.
TextWidget : text_block = text_block{ DefaultText := Message }
# Wrap it in a canvas slot so it can be positioned as UI grows.
Container : canvas = canvas{}
Container.AddWidget(canvas_slot{ Widget := TextWidget })
# Attach the canvas to this player's UI layer — the text now shows on screen.
PlayerUI.AddWidget(Container)
# Background coroutine: simulates streaming values you could bind to a widget.
DynamicUpdates()<suspends> : void =
loop:
Sleep(1.0)
RandVal := GetRandomFloat(0.0, 100.0)
Print("Simulated dynamic value: {RandVal}")
Try it yourself
- Place the
floating_text_devicein your level and drop a Button device nearby. - In the device's Details panel, assign the Button to Interact Button.
- Build Verse Scripts, then playtest and press the button — the text appears in the upper-left of the screen.
- Edit Message in the Details panel to change the displayed text, or extend
DynamicUpdatesto store atext_blockreference and refresh it live.
Recap
You wired a button's InteractedWithEvent to a handler, safely cast the interacting agent to a player, and used the fallible GetPlayerUI[] to reach the UI layer. From there you built a text_block, placed it inside a canvas slot, and attached it with AddWidget. Because UI is per-player, always start from a player-specific event and treat player/UI resolution as fallible. Swap the message and background loop for damage numbers, loot popups, or live stats to scale the pattern.
Check your understanding
Test yourself with an interactive quiz and track your progress + earn XP — free for members.
Turn this into a guided course
Add Spawning Dynamic Floating Text Widgets via Verse Ui Functions to your free study plan — we'll suggest related pages and stitch the lot into one compile-checked, self-guided lesson with worked examples and quizzes.
Original tutorial generated by Verse Island from the Verse/UEFN knowledge base, with references to the Epic Games sources above. Code is validated against the knowledge base.