How to tell which button was clicked?

I have a blueprint to generate buttons dynamically:

Now, I need a way to figure out which button was pressed.

How do I do that?

Hey @NeilAgg!

Do you have a specific reason you’re doing it this way instead of using the UMG for this purpose?
As far as which button was clicked, you need to promote the button to a variable, or add it to an array. Then use a “switch on int” to determine which button was pressed and therefore use that line of execution.

I’d suggest switching to the UMG system, personally, it’s going to save you loads of time based on that amount of code alone.

1 Like

@Mind-Brain Just wondering what you mean by “this way instead of using the UMG”, all I see here is the code tab of UMG with classes used by UMG :thinking: . Which is exactly what you do to “dynamically” aka procedurally generate content. This is more productive than manually adding lists of items on the designer tab and expected to be done by either the designer or the programmer preparing base classes for the designer to well… design on.

@NeilAgg for the question, You add a delegate with a single parameter of the button type (object reference, the blue pin) which in blueprint I believe is called an event dispatcher. on that red node on your screenshot you call the event dispatcher (broadcast) , with the parameter pin attached to the button which was just clicked. Another object can listen to such broadcast, and they will receive a direct pointer to the button which was passed as argument.

https://www.youtube.com/watch?v=ayCEqL7XFZY

https://www.youtube.com/watch?v=sEcoWGrF1Hg

@Roy_Wierer.Seda145 Embarrassing. This is what I get for skipping my morning coffee. Looking back I don’t know what I was thinking with using an array instead of simply a single object reference, either.

@NeilAgg Disregard my post, Seda’s event dispatcher suggestion is the correct way to go about this.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.