Download

Getting all Widgets of type within a Widget Class

Hello,

I have a Widget class called MainMenu which contains buttons and text boxes placed into UVerticalBox instances which those boxes are of type UPanel.

I am trying to use the Widget Class (MainMenu) to find all widgets of type Vertical Box to store upon initialization. It seems the Blueprint only provides access to Find All Widgets of class, and there lists all of the Widgets I have created using Blueprint (in other words, Blueprint widgets). However, I want to store all VerticalBox Panel Types found in the Widget Class at initializationt.

Why? Because I have a large menu scheme, and instead of having to create these cumbersome combinations of when I click this button, I want to hide these vertical boxes and show these vertical boxes… I can instead create a function that takes in one argument: an array of panel objects I want to show. The function would take iterate through the array of vertical boxes I populated at initialization, set visibility to Hidden for all of them. Then iterate through the array argument and set visibility to Visible for all of them.

I am aware you can click IsVariable on the widget object inside the designer, but that just makes the variable which is only half of a solution.

Is there a way to get all widgets of a certain type within a widget blueprint?

So I figured this out for anyone who wants to know.

By ensuring the root object of the UMG Blueprint is set to a variable, you can call the function: GetAllChildren. This will return an array of all children one level below the root. With these objects, you can then query them to get more information about what’s below them. The problem was I wanted to do automation: If I have main menu buttons in different vertical boxes, I want to have each TextBlock within each Button to have white text when hovered, and black text when not. To do this the simplest way would require forty nodes: Each Button’s OnHoverd and OnUnHovered events. Waste! Now imagine if I wanted to change that to do an animation instead. Also, I don’t want to click a button and have to hide the vertical box its in and unhide another vertical box manually with redundant code. You see the nightmare yet? Time for automation!

Here’s my solution (I encourage constructive criticism, it’s how I grow)

OnInitialized:

HPopulateArrayMainMenuSelectionVerticalBoxes:

HPopuateArrayMainMenuSelectionButtons:

Now, if I want the TextBlock on any Button I hover or don’t hover over, that I identified as a Main Menu selection button to highlight white without having to add another piece of code, I call the following function in tick: