Verse Library verse

02 Example Of Positioning Widgets On The Screen

Manages player-specific UI canvases and toggles widgets on button clicks.

extracted-snippets/documentation/en-us/uefn/positioning-widgets-on-the-screen-in-unreal-editor-for-fortnite/02-example-of-positioning-widgets-on-the-screen.verse

# Source URL: https://dev.epicgames.com/documentation/en-us/uefn/positioning-widgets-on-the-screen-in-unreal-editor-for-fortnite
# Local doc:  epic-docs/documentation/en-us/uefn/positioning-widgets-on-the-screen-in-unreal-editor-for-fortnite.md
# Section:    Example of Positioning Widgets on the Screen
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 messages to display as text in the UI
    TextForMyUI<localizes>(InText : string) : message = "{InText}"

    # 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 =
        # 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