Sorry to hijack and necro the thread, but I haven’t seen a solution anywhere else that doesn’t require set up for every button. This solution only needs a reference to a container with the buttons within it (e.g. a vertical box), making it a lot easier if you have large (or multiple) lists.
Note: The decrements behave oddly with child variables, and there’s no need to create a variable of the child count (when I took the screenshots I even forgot to plug them in!) so instead replace them with a simple subtract math function.
At Event Construct
the widget blueprint loops through all the children (in this case, buttons) in the vertical box. Each button is bound such that it when hovered over (OnHovered) it ‘shouts’ out to a custom function (OnHovered_Cust), and when unhovered over (UnHovered) it ‘shouts’ out to another custom function (OnUnHovered_Cust).
is called it loops through each of the children (buttons) of the vertical box, stopping when one of the buttons is found to be hovered over (IsHovered = true). The child (this time, the text) of that
child button is then found, and the desired colour change is applied.
If this sounds confusing, what we’re doing is taking the vertical box, finding it’s children (buttons), and then finding the children of those children (the text in the buttons). The text box is assumed to be the button’s first child, so the Index in GetChildAt is set to 0.
is called it loops through each of the children (buttons). For every button not being hovered over (IsHovered = false) it resets the text colour.
At Event Construct each button is looped through and bound to an Event Dispatcher, meaning if this method is used for a large number of buttons there may be a brief performance impact whenever it initialises.
Because Event Dispatchers cannot carry information, each time the custom event is called it must loop through the children (buttons) to find which one is being hovered over. This means that for very large lists of buttons there may be a slight delay. This could be improved by splitting large containers into smaller sub containers (e.g. one very large box -> three boxes), so that there are fewer items to search.
Each box would require its own custom hover and unhover events, but this as simple as only the reference to the box (e.g. ‘Vertical Box 140’) would need to be changed. Alternatively, in C++ it might be possible to create a custom bind event with a ‘target’ output, meaning the custom function would be able to target the instigator button directly (avoiding any looping).