how to get click information from dynamically spawned buttons

I have created a widget that dynamically spawns all the buttons required. I am now trying to get each button to set the information required.

issues im facing.

when pressing the button it only gives me the information for the last spawned button

if i add each spawned button to an array it just gives me all the buttons information all at once when I’m only after one button. ive looked at other discussions but none of them have been helpfull

widget logic

inside button logic

I’ve done something similar to this which worked. but I don’t want to have to create hundreds of these if i can help it

You need to create your own class child of the button, in which you need to add a delegate with a parameter (a reference to itself, or an ID that you set after creating a button in the loop), which will allow you to understand which button exactly triggered the event.

I’m not 100% sure what you mean? I have asset a printstring per button which tells me which button is being pressed but im unsure how to get this information in the widget screen

Something like this:

*UPD Don’t forget to call init too (like I did), otherwise the magic won’t work. :sweat_smile:

1 Like