Adding Chilld Box and Button Widget


Hi, how can I achieve this with adding child from blueprint. I have Struct Array , it will create 3 scrollbox after that inside struct array have Array B, will create the button according to struct index.
I manage to spawn it however, the button index is 0,1,2,3,4,5,6. I want each scrollbox 0,1,2.

1 Like

Ok I manage to make it 0,1,2 for each scrolboox by adding child but how to find what index Array A if I click the buttons from Array B ? For instance, If I click Buttons from Array A [2] I want get that index Array A. I can’t get the scrollbox index according which column I click.

1 Like

This is something you’d generally handle with Event Dispatchers.

  • create a user widget that represents a scroll box and populates it with buttons from the array
  • as you create those user widgets in a loop, assign them IDs; you can do it manually via exposed variables if there’s only a handful and you place them by hand
  • register every button’s onClick in that user widget and have the scrollbox user widget propagate its ID via an Event Dispatcher whose delegate is in the widget that created the scroll boxes

If the above seems confusing, consider looking into what user widgets are, and how to handle them. It’s such a vital element of the UMG, one cannot do anything that is modular without them. And the next thing would be to look into how Event Dispatchers work - these shine when we need to perform an action in one object and observe the result in another. Especially when it’s a parent-child relationship, like in your example.

2 Likes

Thanks, event dispatcher works like a charm. Now I can find my Array Index A according to which column I click.

But I’m not sure if im following your point 3. I have to add 2 index variable to my button, for Array A to find the parent index inside the scrollbox and Array B for the button.

  • register every button’s onClick in that user widget and have the scrollbox user widget propagate its ID via an Event Dispatcher whose delegate is in the widget that created the scroll boxes