Easy way of getting all buttons in a widget?

Alright, so I don’t want to do this:

Or the alternative, since it’s literally the same thing:

As you can see here, I’m trying to make a navigatable UI menu (with keyboard or gamepad) but I’m trying to make so that such a thing as a button not being focused (at any given time) — impossible. Multiple times I was able to get a button unfocused, and that is a big no-no when navigating with a gamepad.

I’ve spent hours trying to find a way, but it seems that nobody has gone over something like this, or the answer was just not good enough. This was a solution I figured out to solve this problem. However, this …is just bad. I have over 50 different widget blueprints in my project that all have a ton of different buttons, so manually writing every branch for a simple check-up is simply absurd. Obviously, it is not impossible to do it this way, but it is completely impractical.

Is there a way to get all buttons in a particular widget and check for a currently focused one?

Then I could simply save the focused one, and if none of them are focused, make the “last focused widget” set to keyboard focus. This way, I could write this disaster in a few nodes of code.

Thank you!

Have you tried a “for each loop”? Not sure if this will work for what you’re trying to accomplish…

Thank you for responding! I’ve thought about using loops and when I tried a similar method it didn’t work, now I’ve done what you said, however, it seems to be setting the last focused button constantly and when trying to press another button it doesn’t work, any way around that? I made a branch that asks if the last focused button is focused and if so don’t execute further, but it doesn’t seem to work as expected.

Aha, so it seems that once it has chosen the last focused button, it ain’t doing it anymore for last buttons, I figured that after making a small delay, even though I’m moving around buttons, it doesn’t set them as the last focused button, but rather returns to the originally focused button. I’m not sure how is that happening…

Alright, so it seems to work after I made two different ForEachLoops, one for setting the last focused button, and one for checking if the button last focused button is not focused.
Thank you for this suggestion, it seems it has somehow worked out in the end.

yea man, I wasn’t exactly sure cause honestly I didn’t test my answer. Glad it worked out in the end, but I was trying to spare you from having to do all that logic.

Please do not ever use any Epic service to host images