How to keep rect transform points glued to its anchor points?

Hello I have a UI element that I want to take up the left hand side of the screen. No matter the aspect ratio or screen size, I want this element to cover 50% of the width and 100% of the height. How can I achieve this?

I setup my rect transform as follows and it looked great!

s

But then I expanded my editor window and everything was ruined. The anchors stayed where they should, but the rect transform scaled to no longer keep their points.

How can I fix this issue, allowing the screen UI elements to scale, but keep their anchor points? I have the following canvas settings for reference.

Would you like a video demonstration? Here is a YouTube video of this issue:

Here are the official docs on how to make your UI handle various resolutions and aspect ratios cleanly:

Here are some notes on UI Anchoring, Scaling, CanvasScaler, etc:

Usually you need to choose a suitable ScaleMode and MatchMode in the Canvas Scaler and stick with it 100%. Generally if you change those settings you will often need to redo your UI entirely.

Here’s some more fit-inside-UI-content notes:

https://docs.unity3d.com/Packages/com.unity.ugui@1.0/manual/HOWTO-UIFitContentSize.html

I also use this CanvasScalerOrientationDriver utility to make sharing UI for Landscape / Portrait easier. Read what it does carefully.

The issue appears to be that the element had rotation which results in the scaling behavior returning inverted results.

1 Like

ah, right! I always hated that in ugui, but there might be a good reason for it to be this way.
also, consider using a layout group with a single layout element and play with the Flexible Width/Height properties (you can set them as 0.5 or whatever) if you want a more declarative approach instead of manually moving them