How to acces custom widget as parent through engine widget?

Hello!

If I have an EngineWidget on a CanvasPanel on a CustomWidgetOne on a CustomWigetTwo, and I try to use GetParent on an EngineWidget, it returns CanvasPanel. If I use it on CanvasPanel it returns invalid widget. Can I acces CustomWidgetOne and CustomWigetTwo through EngineWidget? I can’t just use self, because I need universal function for all widgets to get all their parents (including custom).

Example Hierarchy:

  • CustomWigetTwo.
    – CustomWidgetOne.
    — CanvasPanel.
    ---- EngineWidget.

EngineWidget GetParent - Canvas Panel.
CanvasPanel GetParent - invalid widget.

Hi! Can you explain the problem you want to solve?

I want to write a function “GetAllParents”, which will return all the parents of a widget. But it seems like UE 4 doesn’t let me access widgets from a engine widget on a custom widget, which are outside this custom widget with function “GetParent”.

Yeah, as I know User Widgets have their local roots (with null by GetParent()), so it is not possible to make it through to engine layer widgets with that. In fact all that stuff is in UGameViewportClient class.

the best way is to add a “parent” variable in your children and you expose it on spawn, and that way you can set it up and acces parent later

By the way, take a look at this

https://docs.unrealengine.com/en-US/API/Runtime/Slate/Widgets/LayerManager/index.html

You can get it from this

if (World && World->IsGameWorld()) {
	if (UGameViewportClient* ViewportClient = World->GetGameViewport()) {
		auto layerManager = ViewportClient->GetGameLayerManager();
	}
}

Most of Player widgets are slotted to special layers and this layer manager can be used to find any of them