Get ALL children from widget (including grandchild)

Hi,

I’m trying to acces a bool variable inside a widget (let’s call it widget B).
There’s this other Widget A that adds as a child an overlay from Widget B that contains several components (horizontal boxes, vertical, buttons and such). So I can access Widget B from Widget A as a variable.
But I want to access that bool variable that is well below the hierarchy panel in Widget B.
In Widget’s A graph panel I tried “Get all children” from Widget B, but this node only returns the direct child (sons), I’d like to access them all.
There’s the option to get all children, then cast to one specific type, then get all children from that successful cast, then do the same… aaand finally get to that grandgrandgrandson, but that would be a total gibberish.
Chat GPT offers me a solution that doesn’t work. Node Get Widget from Name doesn’t exist, or at least I haven’t found it

It also suggests to Get all children using a For each loop from the first Get all chidren, but that doesn’t work either…
Well, here I am asking if any of you has ever faced this, and how have you sorted this out.
Thanks!

1 Like

Digging through widget hierarchy like this is generally as awkward as you think and requires as poor an implementation as Chat GPT suggests - it’s known for that.


A much better question here is why you’re trying to do it - as in, what is the actual scenario? What are we doing? In case you do not want to spill the beans, one could generally approach things like so:

  • widget A
    • widget B
      • widget C

A can talk to to B and C directly (a dispatch may be more convenient if we create children on the go)
B can talk to C directly.
B can talk to A via an Event Dispatcher.
C can can talk to B via an Event Dispatcher.
C can talk to A via an Event Dispatcher that A should bind - is this your scenario?

Whether it’s static or created dynamically does not matter much really. But again, how to connect the pieces depends on what we’re doing, exactly. There are instances where you must pull data out of an object and loop look-ups are necessary evil. Avoid it if you can, Event Dispatchers work could really well here.

If your main widget is UUserWidget - then you can use UWidgetTree (WidgetTree variable).
Using UWidgetTree you can iterate over ALL widgets with all nestings.

But there are some nuances with NamedSlot (it seems to me that only widgets that are INSIDE the slots got into the main tree, but the slots themselves are not in the main tree), I don’t remember exactly, but there were definitely problems with it and I had to work with it additionally.

Hi again,

I really appreciate your time and help. And the thing with “Why I’m trying to do it?” really helped me here.
Thing is I have a widget that pops in the screen at some point. I can click a button in that widget and it would get stored in a map type variable inside the Game Mode (as a value for a determined Key). Why? Because I want this widget to get added as a child inside another widget that would appear at some ohter moment.
In fact is a widget that shows you the information of an apartment, and if you want you can select that apartment as a favorite, and then when you call the favorites menu it will appear with all the selected favorited apartments.
But finally I noticed I didnt’ need to get that bool variable at all. The only thing I needed to do, and it fixed my jigzaw, was to remove any non desired favorited apartments from the favorited menu (just removing them from the map type variable) and construct the favorites menu again with a simple event calling.
It may have no sense at all explained like this. English is not my first language and my knowledge in blueprinting is partially limited. Thing is that your ¿WHY? really made me think about it, and it came to my mind that a single event would do the trick.
So thanks again for your time and help!

Thanks for your help. Finally I sorted it out using a simple event. I think I was trying to get from A to C without using B and therefore no considering the basic aprox.
I made it work with a very simple and logical solution.

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