# How to get instigator for a UI Button?

**URL:** <https://forums.unrealengine.com/t/how-to-get-instigator-for-a-ui-button/1697292>\
**Category:** Verse\
**Tags:** unreal-editor-for-fortnite, fortnite-creative, question, fortnite\
**Created:** [February 18, 2024, 1:49pm UTC](https://forums.unrealengine.com/t/how-to-get-instigator-for-a-ui-button/1697292 "2024-02-18T13:49:55Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![frenzyisegg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@frenzyisegg](https://forums.unrealengine.com/u/frenzyisegg)\
**Post date:** [February 18, 2024, 1:49pm UTC](https://forums.unrealengine.com/t/how-to-get-instigator-for-a-ui-button/1697292/1 "2024-02-18T13:49:55Z")

</div>

I’m trying to find a way to see who presses a button on the UI and grant them weapons based on that but I don’t know how to find the instigator for the button:

```auto
    OG_Button.OnClick().Subscribe(OG_Pressed)

    OG_Pressed(Message:widget_message):void =
        # [Code to find instigator here]
        OG_Granter.GrantItem(Instigator)
        if (PlayerUI:player_ui = GetPlayerUI[Message.Player], MyUI: overlay = MyMap[Message.Player]?, SelectedButton: text_button_base = text_button_base[Message.Source]):
            PlayerUI.RemoveWidget(MyUI)
           if (MyMap[Message.Player] = false) {}
        return

```

Any suggestions would be appreciated!

---

<div class="post-metadata">

**Author:** ![bananna\_manuk](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@bananna\_manuk](https://forums.unrealengine.com/u/bananna_manuk)\
**Post date:** [February 19, 2024, 12:04am UTC](https://forums.unrealengine.com/t/how-to-get-instigator-for-a-ui-button/1697292/2 "2024-02-19T00:04:25Z")

</div>

```auto
OG_Button.OnClick().Subscribe(OG_Pressed)

```

Does the .Subscribe not send you the agent ?  
do you have an error on that line?

---

<div class="post-metadata">

**Author:** ![Jeremy\_Choud](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/jeremy_choud/32/907645_2.png) [@Jeremy\_Choud](https://forums.unrealengine.com/u/Jeremy_Choud)\
**Post date:** [March 13, 2024, 6:22pm UTC](https://forums.unrealengine.com/t/how-to-get-instigator-for-a-ui-button/1697292/3 "2024-03-13T18:22:06Z")

</div>

When you subscribe to a button press like

Button.OnClick().Subscribe(SomeFunction)

That should pass a widget\_message

So you can subscribe to a function that takes a widget message and then define the player who clicked it like this.

```auto
SomeFunction(Message:widget_message):void=
    Player := Message.Player 
    DoSomething(Player)

DoSomething(Player:player):void=
    ItemGranter.GrantItem(Player)

```

if you have multiple buttons in your UI Code you can use this nifty function and class to pass extra parameters to tell exactly which button has been pressed as well

```auto
(Listenable : listenable(widget_message)).SubscribeMessage(OutputFunc : tuple(widget_message, t)->void, ExtraData : t where t:type) : cancelable =
    Wrapper := wrapper_message(t){ExtraData := ExtraData, OutputFunc := OutputFunc}
    Listenable.Subscribe(Wrapper.InputFunc)
 
wrapper_message(t : type) := class():
    ExtraData : t;
    OutputFunc : tuple(widget_message, t) -> void
    InputFunc(Message : widget_message):void = OutputFunc(Message, ExtraData)

```

So if you had a few buttons like

```auto
button_1: button_quiet = button_quiet{}
button_2 : button_quiet = button_quiet{}

```

you could use the wrapper function SubscribeMessage to pass which button has been clicked like this

```auto
button_1.OnClick().SubscribeMessage(SomeFunction, 0)
button_2.OnClick().SubscribeMessage(SomeFunction, 1)

#then SomeFunction can figure out what to do based on the integer passed into it 

SomeFunction(Message:widget_message, button_index:int):void=
    Player := Message.Player
    if(button_index = 0):
        Item_Granter_0.GrantItem(Player)
    else if(button_index = 1):
        Item_Granter_1.GrantItem(Player)

#or you can have an array of item granters and grab them that way 
@editable Granter_Array :[]item_granter_device = array{}

SomeFunction(Message:widget_message, button_index:int):void=
    Player := Message.Player
    if(Granter := Granter_Array[button_index]):
        Granter.GrantItem(Player)

```
