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.