# Get size of UMG widget

**URL:** <https://forums.unrealengine.com/t/get-size-of-umg-widget/361726>\
**Category:** UI\
**Tags:** unreal-engine, slate, UI, CPP, question, UMG\
**Created:** [June 22, 2016, 8:50pm UTC](https://forums.unrealengine.com/t/get-size-of-umg-widget/361726 "2016-06-22T20:50:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_730dbe67](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_730dbe67](https://forums.unrealengine.com/u/anonymous_user_730dbe67)\
**Post date:** [June 22, 2016, 8:50pm UTC](https://forums.unrealengine.com/t/get-size-of-umg-widget/361726/1 "2016-06-22T20:50:31Z")

</div>

Hey, I want to get the size of a widget inside a child class of UHorizontalBox in C++. Is that possible? `GetDesiredSize()` always returns 0 and I hadn’t have any luck with with anything else I tried so far.

---

<div class="post-metadata">

**Author:** ![Pelangi](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Pelangi](https://forums.unrealengine.com/u/Pelangi)\
**Post date:** [August 9, 2016, 2:06pm UTC](https://forums.unrealengine.com/t/get-size-of-umg-widget/361726/2 "2016-08-09T14:06:32Z")

</div>

I have this problem too in UE 4.12.

---

<div class="post-metadata">

**Author:** ![ScrapingBottom](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@ScrapingBottom](https://forums.unrealengine.com/u/ScrapingBottom)\
**Post date:** [August 25, 2016, 1:34am UTC](https://forums.unrealengine.com/t/get-size-of-umg-widget/361726/3 "2016-08-25T01:34:54Z")

</div>

I also have this problem in 4.11

---

<div class="post-metadata">

**Author:** ![Zcience](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/zcience/32/951950_2.png) [@Zcience](https://forums.unrealengine.com/u/Zcience)\
**Post date:** [April 16, 2017, 11:56am UTC](https://forums.unrealengine.com/t/get-size-of-umg-widget/361726/4 "2017-04-16T11:56:36Z")

</div>

I have found out, that there are two different approaches for this question.

1.: If you want to get the size during initialization of an actor, for example in BeginPlay, when the Geometry of the widget has not already been calculated, you can use the following code:

```
 UPanelSlot* examplePanelSlot = ExamplePanelWidget->Slot;
 UCanvasPanelSlot* exampleCanvasPanelSlot = Cast<UCanvasPanelSlot>(examplePanelSlot);
 FVector2D examplePanelSize;
 if (NULL != exampleCanvasPanelSlot) {
    	examplePanelSize = exampleCanvasPanelSlot->GetSize();
 }

```

But this only works, if the UUserWidget\* ExamplePanelWidget actually has an UCanvasPanelSlot, for example if you’re using an Overlay or HorizontalBox.

You can see the kind of Slot in the UMG Blueprint, if you select the widget and go to the Details-Panel, for example:

![134416-ucanvaspanelslotexample.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/9/a/99a0430769d823d58d36ac3def7cd88e679ca21f.png)

2.:You can get the size during runtime from the Geometry of the widget:

```
  FGeometry cachedGeometry = ExamplePanelWidget->GetCachedGeometry();
  FVector2D currentSize = cachedGeometry.GetLocalSize();

```

But if you try this before the Geometry of the Widget was calculated the first time – for example during BeginPlay – you will get a zero vector.

---

<div class="post-metadata">

**Author:** ![Rumbleball](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Rumbleball](https://forums.unrealengine.com/u/Rumbleball)\
**Post date:** [July 4, 2017, 12:01am UTC](https://forums.unrealengine.com/t/get-size-of-umg-widget/361726/5 "2017-07-04T00:01:52Z")

</div>

I’m over this right now, as I want to fill a vertical box with as many text widgets as fit in without scrolling. But the size of the text can vary as well as the rendersize of the widget.

I got myself to the part with the cachedGeometry and that is 0 at time of building the widget (in RebuildWidget). But at what point is the geometry calculated? Can I force the calculation? The widget is placed in a WidgetComponent.

---

<div class="post-metadata">

**Author:** ![highdev](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@highdev](https://forums.unrealengine.com/u/highdev)\
**Post date:** [December 10, 2018, 6:50am UTC](https://forums.unrealengine.com/t/get-size-of-umg-widget/361726/6 "2018-12-10T06:50:03Z")

</div>

Thanks, you are right
