Verse Library verse

10 Removing A Widget

Complete device implementation that subscribes to button events and toggles a player-specific UI widget on or off.

extracted-snippets/documentation/en-us/uefn/creating-and-removing-widgets-in-unreal-editor-for-fortnite/10-removing-a-widget.verse

# Source URL: https://dev.epicgames.com/documentation/en-us/uefn/creating-and-removing-widgets-in-unreal-editor-for-fortnite
# Local doc:  epic-docs/documentation/en-us/uefn/creating-and-removing-widgets-in-unreal-editor-for-fortnite.md
# Section:    Removing a Widget
 using { /Fortnite.com/Devices }
 using { /Verse.org/Simulation }
 using { /UnrealEngine.com/Temporary/UI }
 using { /Fortnite.com/UI }
 using { /UnrealEngine.com/Temporary/SpatialMath}

 hello_world_device := class(creative_device):

     # Set the Button device in the Editor to reference the device in the level
     @editable
     MyButton : button_device = button_device{}

     # A localizable message to display as text in the UI
     TextForMyUI<localizes> : message = "Hello, world!"

     # A mapping between the Player and the widget that may have been added to their UI
     var MaybeMyUIPerPlayer : [player]?text_block = map{}

     # Runs when the device is started in a running game
     OnBegin<override>()<suspends> : void =
         MyButton.InteractedWithEvent.Subscribe(HandleButtonInteraction)

     # 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]):

Sign in free to read the full source 🌴

This Verse Library file is members-only. Create a free account to view the complete source and download the .verse file.

Sign in with Discord

Comments

    Sign in to vote, comment, or suggest an edit. Sign in