How to currectly get the size of user widget?

Hi, everyone:

I want to get the size of my widget in its own preconstruct event for preview layout, I have tried:
Self–>SlotAsCanvasSlot–>GetSize

but it only works when the anchor of this widget is top-left, I can only get the offset if the anchor is “top-fill”.
I have tried
Self–>GetCachedGeometry->GetLocalSize

but this only works at runtime.

Is anyone can tell me how to get the size of an widget in its own PreConstruct evenet? Thank a lot for your time.

Hi, everyone, I have found out what I need, it quite simple, just add a delay node before get the size from cached geometry:

In PreConstructEvent::

Delay(0);
RootCanvas–>GetCachedGeometry–>GetLocalSize

If you want to get the runtime size in widget tick, you can:

GetTickSpaceGeometry–>GetLocalSize

Hope that helps.

3 Likes

This works in blueprint too. Helps me preview how my widget will look in editor.

1 Like