Hi there, I’m trying to get the size of a widget. I know I can do this like in the example below:
However, this doesn’t work with an auto-sized widget (“Size to content” inside of a canvas), because it always returns the size the widget has before it gets auto-sized. How can I get the final size the widget has when it’s displayed with auto size?
Jiyko
(Jiyko)
September 26, 2018, 8:10pm
2
Ever find an answer to this?
Returns 0,0 in this case, that’s not what I need. There’s this node:
But instead of just saying if It’s autosized or not I need the actual Vector2.
Get Desired Size is what you are looking for. But you need to call it after some delay.
Everynone
(Everynone)
November 6, 2018, 7:28am
6
That’s what ForceLayoutPrepass is for. Delay 0.0 should also work but it’s more of a hack.
2 Likes
Sorry, forgot to answer this, ForceLayoutPrepass worked for me, thank you!
How are you using ForceLayoutPrepass? I can’t get the final auto-sized dimensions no matter what I try.
Just call the ForceLayoutPrepass BEFORE you return the size of your autosized widget.
Thank you for the visual!
Koulounil
(Koulounil)
August 9, 2022, 5:19pm
11
In case that helps, here’s how I’m doing it in C++ :
FVector2D USpacerHelper::GetWidgetSize(UWidget* Widget)
{
FGeometry AbsoluteGeometry = Widget->GetCachedGeometry();
return FMath::Min(AbsoluteGeometry.GetAbsoluteSize(), Widget->GetDesiredSize());
}
1 Like