Verse Library verse

04 Button Interactions

Defines a creative device class that manages player-specific interactive UI widgets triggered by button events.

extracted-snippets/documentation/en-us/fortnite/making-widgets-interactable-in-unreal-editor-for-fortnite/04-button-interactions.verse

# Source URL: https://dev.epicgames.com/documentation/en-us/fortnite/making-widgets-interactable-in-unreal-editor-for-fortnite
# Local doc:  epic-docs/documentation/en-us/fortnite/making-widgets-interactable-in-unreal-editor-for-fortnite.md
# Section:    Button Interactions
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{}
# Localizable message to display as text in the UI
TextForMyUI<localizes> : message = "Option"
# A mapping between the Player and the widget that may have been added to their UI
var MaybeMyUIPerPlayer : [player]?canvas = 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 =
if (InPlayer := player[Agent], PlayerUI := GetPlayerUI[InPlayer]):
if (MyUI := MaybeMyUIPerPlayer[InPlayer]?):
PlayerUI.RemoveWidget(MyUI)
if (set MaybeMyUIPerPlayer[InPlayer] = false) {}
else:
NewUI := CreateMyUI()
PlayerUI.AddWidget(NewUI, player_ui_slot{InputMode := ui_input_mode.All})
if (set MaybeMyUIPerPlayer[InPlayer] = option{NewUI}) {}
CreateMyUI() : canvas =

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