Is there a way to get the string name of button pressed?

If I have button named “button1234” and another button named “button5678” for example, is there a way to get the name of the button pressed?

Pseudocode of what I mean:

button1234.InteractedWithEvent.Subscribe(HandleMyButton)
button4567.InteractedWithEvent.Subscribe(HandleMyButton)

HandleMyButton(Agent: agent):
get string of the button pressed to get to this function like
#Agent.buttonStringOrOtherwayToGetInfoAboutWhopressedme
if(button1234):
Print(“Foo”)
if(button4567):
Print(“Bar”)

I was looking for a solution to this issue today also and came across this post. I was sad to see it didn’t have an answer, however I was just watching some YouTube videos and came across the perfect solution.

There is a wrapper code for the Subscribe function that allows you to pass variables.

So you can have:

Button1.InteractedWithEvent.SubscribeAgent(OnButtonPressed,”Button1”)

Button2.InteractedWithEvent.SubscribeAgent(OnButtonPressed,”Button2”)

And you’ll be able to access “Button1” and “Button2” in your function.

There is a snippet of code you need to add to your file first, but you might as well just watch this video which explains it all. Start from 1:30

Hope this helps!

1 Like

This is extremely helpful thanks! Exactly what I needed :slight_smile: smile: