Constrain UMG's aspect ratio?

I was just wondering if there was any way to constrain a UMG widget to 16:9 in game, as it doesn’t seem to follow the player’s camera’s aspect constraint?

Thanks :slight_smile:

Can you post an image showing what you’re trying to achieve? How would the constraining work?

Well, when you constrain a normal camera’s aspect ratio, in editor black bars appear over and under (I constrain it to 16:9)

However, there is no such setting for UMG, so if I’m playing my game, with the black bars because its constrained, and I create a UMG widget and add it to viewport, it takes up the whole viewport, and not just the constrained part.

Just checking, yeah we don’t lock the UI to any constraints set on the camera, probably should.

The offhand way I think you could fake it would be to make your root widget on any fullscreen UI you have a SizeBox set to the 16:9 resolution you want to be the nominal scale 1 resolution for your games UI. Then place that inside a ScaleBox set to scale to fit, and disable the DPI Scaling curve, otherwise you’d get double scaling.

Alternatively, you’d need to manually determine how big the canvas should be after placing it in the viewport, and adjust it’s size and position to match the black bars.

Ok, thank you for answering :slight_smile:

Are there any plans to change it to fit in the camera automatically?

Are you guys ever going to constrain UMG to the camera?

Seriously, this is a big problem. We need user interface elements to constrain to the camera’s aspect ratio.

Alternatively, you’d need to manually determine how big the canvas should be after placing it in the viewport, and adjust it’s size and position to match the black bars.

Could you provide a screenshot of blueprints showing how this is done?

  1. In Project Settings, Set ‘DPI Scale Rule’ to ‘Custom’
  2. Create a C++ class inherited from UDPICustomScalingRule, and override the function GetDPIScaleBasedOnSize(FIntPoint)
  3. In Project Settings, assign the class to ‘DPI Scaling/Custom Scaling Rule Class’

the pesudo code of the function could be like this:

float aspect = ScreenSize.y / ScreenSize.x;
if (aspect > FixedAspect)
    return ScreenSize.x / FixedWidth;
else
    return ScreenSize.y / FixedHeight

And when Editing UMG, use FixedWidth and FixedHeight as your design screen size

widget root - scale box (scale to fit) - overlay (align center) - border - everything else.

1 Like

I can’t believe it doesn’t lock UI to camera aspect ratio, this is a huge design flaw!

1 Like

Sorry to bump this thread but has anyone figure this out? Losing my mind trying to solve this.

Jeez are we really still waiting for this feature? It’s been 8 years since this problem was brought up and we still don’t have a proper locking to aspect ratio option :slightly_frowning_face:

1 Like

This works good enough for my purpose. If allowing any-sized windowed mode, then I did find a few odd sizes that results in the scene camera extending slightly past the UI’s border. Otherwise a great solution and probably good enough for most.

There may be 2 way to try to do this(i will try later)
1:Using a fake resolution when you choose to a different aspect ratio resolution, it also uses the local viewport resolution, so the UMG will be a right aspect ratio, they will not be stretching. You have to set the target aspect ratio to camera, so the game viewport will cut unnecessary game graphics, but the problem is your mouse still can move to the outside and you have to set a mask to cover outside game graphics,also you have to reset all UI position or create a empty ui to fill the outside space,that`s low efficiency…

2:Try to Change the Windows System Resolution and aspect ratio both, it seems to use c++ to do this, and then change game resolution too,it may work prefact and no stretching, it just like to set the windows screen to another aspect ratio and the graphics will not to fill the display, and when you exit game, restore the screen resolution and aspect ratio.

i think the second way is the simple way to do this even the player will get black screen for a few seconds to change the Windows System Resolution, but it seems so many games do that…