How to activate triggers for Verse made UI

UEFN only allows 6 buttons to activate when trying to make a Canvas UI and since i needed way more, i made my UI with Verse. The issue I am having is that I want each button to trigger their own trigger device, but i’m not sure how to go about this. The issue is that the trigger.Trigger() requires a player object as a parameter, and button.OnClick.Subscribe() sends a widget_message, the widget_message struct does have a player object. I eventually just ended up hard coding all the events, but i am wondering there is a better way to do it. My code looks something like this

@editable Triggers : trigger_device = array{}

CreateUI(Player: player):void=
MainCanvas := canvas{}
set ButtonCounter = 1

    ... (Anchor and offset positioning)

    case(ButtonCounter):
                1 =>
                    Button.OnClick().Subscribe(Button1Pressed)
                2 =>
                    Button.OnClick().Subscribe(Button2Pressed)
                3 =>
                    Button.OnClick().Subscribe(Button3Pressed)

               ...

    set ButtonCounter += 1
    return MainCanvas

Button1Pressed(Widget: widget_message): void=
if(Trigger := Triggers[0]):
Trigger.Trigger(Widget.Player)

Button2Pressed(Widget: widget_message): void=
if(Trigger := Triggers[1]):
Trigger.Trigger(Widget.Player)

Button3Pressed(Widget: widget_message): void=
if(Trigger := Triggers[2]):
Trigger.Trigger(Widget.Player)

Unless I’m missing something, I’m pretty sure there is a trigger_device.Trigger() that doesn’t take any parameters :thinking:. Check the docs here.

There is an overloaded Trigger method that does take an agent, you can see it here

Anyways i found out that i can just create an async function that awaits a button press with Button.OnClick().Await()

Im still pretty new to UEFN and Verse and didn’t know it existed

1 Like

Alternatively, there’s a way to subscribe and pass some additional data
https://dev.epicgames.com/community/snippets/d8k/fortnite-wrapping-subscribe-to-pass-additional-data-to-listeners

You’d have to modify it to accept a widget_message, something like this

(Listenable : listenable(widget_message)).SubscribeWidget(OutputFunc : tuple(widget_message, t)->void, ExtraData : t where t:type) : cancelable =
    Wrapper := wrapper_widget_message(t){ExtraData := ExtraData, OutputFunc := OutputFunc}
    Listenable.Subscribe(Wrapper.InputFunc)

wrapper_widget_message(t : type) := class():
    ExtraData : t;
    OutputFunc : tuple(widget_message, t) -> void
    InputFunc(WidgetMessage : widget_message):void = OutputFunc(WidgetMessage, ExtraData)

Then you could subscribe with

Button.OnClick().SubscribeWidget(ButtonPressed, ButtonCounter)

And use the same function to trigger any of them

ButtonPressed(Widget: widget_message, ButtonCounter): void=
    if(Trigger := Triggers[ButtonCounter]):
        Trigger.Trigger(Widget.Player)