How can I get the size of a widget in UMG?

I want to custom a scrollbox ,but I can not get the size of my scrollbox and the widget I put in it, I guess "I just want to get the size of a widget " that mey be a simple question, please! who can help me? and forgive my bad english.

Hello, libohan1312

To do this, you can use UUserWidget::SetDesiredSizeInViewport function:

UFUNCTION(BlueprintCallable, BlueprintCosmetic, Category="User Interface|Viewport")
void SetDesiredSizeInViewport (FVector2D Size)

Hope this helped!

Good luck!

Thinks , do you mean that get the size manually? can I get it dynamic in the running time? I hava extended the scrollbox, I want to get the size of the widget added in it.

Hey Libohan,

I may have found a way to get the size of a widget but its a little long winded to get there. Basically put your widget within a container, like a vertical or horizontal box. Make that container a variable so you can get it’s size.

I hope this helps :slight_smile:

yes! I think it works , I find only canvas solt can get its childrens size, thanks.

this works perfect

Best way in cpp is

GetCachedGeometry().GetLocalSize()

Or in BPs :

338594-untitled.png

2 Likes

I cannot open the BP link :frowning:

Another way, one that worked best for me, was to use the “Get Scroll Offset Of End” node from my scrollbox and use that as a clamp on the offset I applied via my input.

Input * scrollSpeed + GetScrollOffset (current offset) → Clamped between 0 (top of scrollbox) and GetScrollOffsetOfEnd (end of scrollbox) → pipe return into SetScrollOffset node.

Blueprint : Get Cached Geometry (returns a Geometry), Get Local Size (takes in a geometry) …

Really nice one, thanks