# UMG: How to scale a widget to X% of actual viewport size?

**URL:** <https://forums.unrealengine.com/t/umg-how-to-scale-a-widget-to-x-of-actual-viewport-size/412988>\
**Category:** UI\
**Tags:** size, unreal-engine, scaling, Widget, question, dpi, UMG\
**Created:** [December 23, 2017, 1:28pm UTC](https://forums.unrealengine.com/t/umg-how-to-scale-a-widget-to-x-of-actual-viewport-size/412988 "2017-12-23T13:28:06Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![polygon](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@polygon](https://forums.unrealengine.com/u/polygon)\
**Post date:** [December 23, 2017, 1:28pm UTC](https://forums.unrealengine.com/t/umg-how-to-scale-a-widget-to-x-of-actual-viewport-size/412988/1 "2017-12-23T13:28:06Z")

</div>

I’m having some serious trouble with UMG and I hope that you can help me 🙂

In general I want so scale an image so that it’s dimensions equals X% of the current viewport size but I can’t manage to do this properly. Here’s what I did:

- I created a standard widget and added a size box with an image in it (see settings in the attached screenshot)

 ![224856-02-settings.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/3/7/d37d7079836854ff383cbc8fab41f3a7ca72feb7.jpeg)

- Via script I get the current viewport size, calculate 10% of the size and override the dimensions of the size box

 ![224855-01-screenpercentage.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/d/0/7/d07aaac7f663454b7b871a0e78fb4ed047a7c35a.jpeg)

- I print the results on screen but as you can see in the attached images, the dimensions of the size box do not match any logical size relative to the viewport resolution
- Example a) The viewport’s x width is 1920 pixels and the dimensions of the Sizebox should be 192x192 pixels (which is 10% of the viewport’s X size) but it’s dimensions are 180x180 pixels:

 ![224853-1920.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/b/1/0b10c2e689ca617dc0c2110c115610b37417a4d6.jpeg)

- Example b) The viewport’s x width is 640 pixels and the dimensions of the Sizebox should be 64x64 pixels (which is 10% of the viewport’s X size) but it’s dimensions are 28x28 pixels

 ![224854-640.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/6/1/e/61ea14d5ae742932b13d0bbcd2fd88e492d91718.jpeg)

Thanks in advance and best regards,  
Daniel

---

<div class="post-metadata">

**Author:** ![polygon](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@polygon](https://forums.unrealengine.com/u/polygon)\
**Post date:** [December 23, 2017, 3:34pm UTC](https://forums.unrealengine.com/t/umg-how-to-scale-a-widget-to-x-of-actual-viewport-size/412988/2 "2017-12-23T15:34:20Z")

</div>

I think I just found the solution:

 ![224873-solution.jpg](https://d3kjluh73b9h9o.cloudfront.net/original/4X/0/a/9/0a9de5b583622b5e46e87a6fb11dc8120b6ab012.jpeg)

---

<div class="post-metadata">

**Author:** ![vinstriano](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@vinstriano](https://forums.unrealengine.com/u/vinstriano)\
**Post date:** [January 6, 2019, 12:15pm UTC](https://forums.unrealengine.com/t/umg-how-to-scale-a-widget-to-x-of-actual-viewport-size/412988/3 "2019-01-06T12:15:09Z")

</div>

Where you put this function?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_9f003c31](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_9f003c31](https://forums.unrealengine.com/u/anonymous_user_9f003c31)\
**Post date:** [June 4, 2021, 9:40am UTC](https://forums.unrealengine.com/t/umg-how-to-scale-a-widget-to-x-of-actual-viewport-size/412988/4 "2021-06-04T09:40:47Z")

</div>

by referencing the answer by @polygon’s , i am able to set the size as below

 ![340662-ue4-canvasscaling.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/9/e/e/9ee0dda7dd1014ea638ab2c36d05f4ac06d1ba54.png)

 ![340665-ue4-canvasscaling-2.png](https://d3kjluh73b9h9o.cloudfront.net/original/4X/5/1/d/51d2e3000d7ca624eeaf3e447a5bfd936e3f698e.png)
