Was creating dynamic button, the button widget was suppose to use event dispatcher. But the bind to the event dispatcher is only getting the last created buttons command.

I was trying to create data driven button menu. In button widget, the buttons was suppose to fire their respective task (like setting up particular texture) so i was using event dispatcher to send info to the menu widget. But the bind to the even dispatcher is only receiving the info of the finally created button (i.e. last index button).

This the button widget

Calling the event dispatcher, here when i press different button it prints their respective index number every time without fail . ( In Button Widget)

Creating dynamic buttons with the info from data table and displaying in uniform grid panel. ( In Main menu Widget)

To receive their respective Row name of the data table to set a image texture which is also save in the data table. (In Main Menu Widget)

Please can some one point out my mistake, or if u guys have other method it would really help me. What is the problem with the event dispatcher and why is it only firing when the last button is pressed. Is there any other alternative way to access the dynamically created button and assign different task to fire.

Thank you guys!!

You’re overriding each reference and eventually bind the very last one only. Instead, bind the buttons as you create them here:

This way you do not not even need a hard reference - which is one of the more important aspects of using dispatchers. A reference var can only hold a ref to a single object. You could use an array (or fetch container content) but that defeats the purpose.


You can can also do it it like so:

A function instead of a custom event would work, too.

Worked like a charm, Thanks man!!!