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

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

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)

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

  • 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:

  • 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

Thanks in advance and best regards,
Daniel

I think I just found the solution:

2 Likes

Where you put this function?

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

1 Like