# Source URL: https://dev.epicgames.com/documentation/en-us/fortnite/creating-and-removing-widgets-in-unreal-editor-for-fortnite
# Local doc: epic-docs/documentation/en-us/fortnite/creating-and-removing-widgets-in-unreal-editor-for-fortnite.md
# Section: Removing a Widget
# A custom UI can only be associated with a specific player, and only that player can see it
HandleButtonInteraction(Agent : agent) : void =
# Agents can be a player or AI, but you can only get the UI of a player
# so you must cast the Agent, who interacted with the Button device, to the player type
if (InPlayer := player[Agent], PlayerUI := GetPlayerUI[InPlayer]):
if (MyUI := MaybeMyUIPerPlayer[InPlayer]?):
PlayerUI.RemoveWidget(MyUI)
if (set MaybeMyUIPerPlayer[InPlayer] = false) {}
else:
NewUI := text_block{DefaultText := TextForMyUI}
PlayerUI.AddWidget(NewUI)
if (set MaybeMyUIPerPlayer[InPlayer] = option{NewUI}) {}
Verse Library
verse
05 Removing A Widget
Toggles a custom text widget on or off when a player interacts with a button device.
extracted-snippets/documentation/en-us/fortnite/creating-and-removing-widgets-in-unreal-editor-for-fortnite/05-removing-a-widget.verse