How to automatically assign OnHover and OnClick events with different parameters?

I have 15 UMG buttons in an array that trigger 15 corresponding animations then go to their respective level. Basically, 15 buttons calling the same function with different paramenters.

I was trying to use a for loop to automate this task, but the parameters will be overwritten during the loop, so all buttons will always call the function with the last parameters passed.

How can I automate this task and get functions that know which button called them?

You can create a new Event Dispatcher in your button widget with an integer Input value, an Input Value for matching your button type and then a variable in the button widget for your index.
In your button widget just use the button on clicked event to fire the custom dispatcher and use the newly “LocalIndex” variable as an input for your dispatcher and for SelfButton use “Self”
This is how it would look like:

1 Like

Thank you so much. I had no idea about how to use event dispatchers neither that I had to make a new separate class for the buttons, it’s working now.

As a beginner, I thought I could simply place all elements in the same widget blueprint class.

1 Like

No problem!

Glad it works now :slight_smile: