Hello!
Is there any way to get UserWidget object that is parent for Widget (like a button, text block, etc.)
Get parent returns Widget element, but not UserWidget object
Hello!
Is there any way to get UserWidget object that is parent for Widget (like a button, text block, etc.)
Get parent returns Widget element, but not UserWidget object
Iβm not sure I understand your question, but if youβre getting a widget as a return of GetParent it might mean your button is parented to a widget that in turn is part of your userwidget. In that case what you need to do is to call GetParent again on the output of your first GetParent; or anyway repeat this if you have nested widgets until you get to your userwidget
No, it doesnβt work
I call GetParent() on CanvasPanel and it always returns null
The method I use is to add a variable into the widget that is going to be the child of the class of the intended parent and expose it on spawn, then when you create the widget you can just add a reference to self to the input for that variable.
Hey,
i was looking for this and i found the answer, you need to use the βouter objectβ
in my cas i was calling it in an child user widget
container userwidget ( i want to get this )
overlay
canvas
child userwidget ( i'm calling from here )
unless you do fancy stuff with outer object allocation, this should return the first parent canvas
best regards
Paulo Egidio
Multiverse Designer
UCanvasPanel* GetParentCanvas(UWidget* widget)
{
UCanvasPanel* Canvas = nullptr;
do
{
startloop:
auto candidate = widget->GetParent();
if (candidate == nullptr)
{
// try outer object
UObject* outter = widget;
while (true)
{
outter = outter->GetOuter();
if (outter == nullptr)
return nullptr;
auto w = Cast<UWidget>(outter);
if (w != nullptr)
{
widget = w;
goto startloop;
}
}
}
else
widget = candidate;
Canvas = Cast<UCanvasPanel>(widget);
} while (Canvas == nullptr);
return Canvas;
}
Excellent, this helped me a lot today: Parent->Outer->Outer->Cast
works great. It seems that just Outer->Outer->Cast
works as well, since the result from the first Outer is always the tree structure.
Iβm working on some UI now and just wanted to chime in since I stumbled upon this post.
Just a tip here. You donβt have to go through hierarchy like that. It becomes inefficient if you have a lot of elements.
Just use CommonUI Find Parent Widget of Type node if you are looking for an actual parent widget class of the sub widget and not the container element/s.