# Adding Custom Events To Widgets In A For Loop

**URL:** <https://forums.unrealengine.com/t/adding-custom-events-to-widgets-in-a-for-loop/2261582>\
**Category:** Blueprint\
**Tags:** for-loop, unreal-engine, Blueprint, question\
**Created:** [January 5, 2025, 10:03pm UTC](https://forums.unrealengine.com/t/adding-custom-events-to-widgets-in-a-for-loop/2261582 "2025-01-05T22:03:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![befrf1331](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@befrf1331](https://forums.unrealengine.com/u/befrf1331)\
**Post date:** [January 5, 2025, 10:03pm UTC](https://forums.unrealengine.com/t/adding-custom-events-to-widgets-in-a-for-loop/2261582/1 "2025-01-05T22:03:48Z")

</div>

Sorry if this has been asked before. I’ve been trying to figure this out and I can find no apparent solution. So I’m making a character creation screen. I have a data table with all the classes in the game which gets iterated through and a button gets added for each class. My current understanding is the way you add functionality to buttons is through custom events. My problem is when adding custom events in a for loop it doesn’t work. Here are screenshots of how it works now:

 ![Screenshot from 2025-01-05 10-09-51](https://d3kjluh73b9h9o.cloudfront.net/original/4X/e/e/c/eec8cee9f56b987c3f3e5df1d7f1e79835f9d8b9.jpeg)

This is suboptimal because it means every time I add new classes i need to go back in here and update it with the new class IDs. I’d really prefer to just make it once and have it loop through all the classes, make the buttons and make custom events for each button added which do what I want them to.

This is what I tried, but it obviously isn’t going to work:

 ![Screenshot from 2025-01-05 10-15-39](https://d3kjluh73b9h9o.cloudfront.net/original/4X/c/0/1/c01e37099d3e1430aad92e9a1dfbdf84be44a997.png)

There’s gotta be a way to make this work. I’m just missing something. Thanks for any responses.

---

<div class="post-metadata">

**Author:** ![zeaf](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/zeaf/32/1108035_2.png) [@zeaf](https://forums.unrealengine.com/u/zeaf)\
**Post date:** [January 5, 2025, 10:52pm UTC](https://forums.unrealengine.com/t/adding-custom-events-to-widgets-in-a-for-loop/2261582/2 "2025-01-05T22:52:17Z")

</div>

Why not just handle this logic in the button itself?  
Initialize it with the data that it needs, and then in its own blueprint, on clicked, do what you’re supposed to  
Remember there’s nothing stopping you from broadcasting another delegate that has more information, and not rely on OnClicked. So you can bind to a new delegate that has all the information you need, which is broadcast through OnClicked in the button blueprint. That way you can still handle all the logic in the main widget that you’ve shown. For example you can initialize each button with perhaps the whole Character Class Data struct, so then the button itself knows everything about the class it represents, including the ID. Then the button can broadcast a new event (OnClassSelected) for example, with the data it has as a parameter, making it very easy to react to that

---

<div class="post-metadata">

**Author:** ![befrf1331](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@befrf1331](https://forums.unrealengine.com/u/befrf1331)\
**Post date:** [January 6, 2025, 10:31am UTC](https://forums.unrealengine.com/t/adding-custom-events-to-widgets-in-a-for-loop/2261582/3 "2025-01-06T10:31:19Z")

</div>

This is an excellent suggestion! I was able to solve the problem with this advice. I made a new more specific button widget just for the class. I made a function that accepted all the relevant information and references, and set local variables. Off of the on clicked node in the event graph, I used the local variables I set to perform all of the actions I previously had in the custom events. I got rid of the custom events, and simply called the function to set all the variables inside each button that was created. Here’s what the graphs look like now: (These screenshots aren’t for class, but for a simpler case with the same issue called “Kind” but if it works for this, it will work for the class as well)

Kind event graph:

 ![Screenshot from 2025-01-06 04-25-38](https://d3kjluh73b9h9o.cloudfront.net/original/4X/8/9/7/8971d8ec28175339d3ef222eb227f86c0959e536.png)

Kind Button Update Function:

 ![Screenshot from 2025-01-06 04-28-52](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/d/2/2d289b5b9b0e37e5f9870b0033c929e53c83940c.png)

Kind Button Event Graph:

 ![Screenshot from 2025-01-06 04-27-18](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/0/f/d0fc89b90f8109f773ad2a3908174c5d1de7eccd.png)

I thought I’d include screenshots of what worked in case anyone else has this problem in the future.

Thank you so much for your help!

---

<div class="post-metadata">

**Author:** ![system](https://d3kjluh73b9h9o.cloudfront.net/original/4X/7/1/3/713c9d3f58553f0de89543d76a8a3a2779dc9fa4.png) [@system](https://forums.unrealengine.com/u/system)\
**Post date:** [February 5, 2025, 10:31am UTC](https://forums.unrealengine.com/t/adding-custom-events-to-widgets-in-a-for-loop/2261582/4 "2025-02-05T10:31:20Z")

</div>

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