Get size of auto-sized widget

Hi there, I’m trying to get the size of a widget. I know I can do this like in the example below:

233740-sizeofwidget.png

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?

Ever find an answer to this?

Get Desired Size.

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. :smiley:

Get Desired Size is what you are looking for. But you need to call it after some delay.

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! :slight_smile:

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. :slight_smile:

Thank you for the visual!

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