1
\$\begingroup\$

I created a very simple scene, to understand how screen scaling works in Unity. The scene has only a SpriteRenderer object and a TextMeshPro object - no Canvas or other UI elements. The TextMeshPro object is set to "Auto Size" (the SpriteRendered does not have such setting). Here is what happens when I change the screen size:

enter image description here

With a fixed aspect ratio, both the text and the sprite change their size, both when I change the height and when I change the width. But with a free aspect ratio, the text and the sprite change their size when I change the height, but NOT when I change the width.

This is quite confusing. What exactly would happen when I run the games on real screens - would the text and image scale appropriately? If not, what should I do in order to ensure that the text and image always scale?

NOTE: When I uncheck the "Auto Size" setting of the TextMeshPro, I get exactly the same behavior. So I am not sure why it is needed.

\$\endgroup\$
0
3
\$\begingroup\$

By default, Unity scales the camera view of your 3D world to fit the height of the window. That simple rule is the only thing happening in both of your examples:

  • When you've fixed the aspect ratio of the window, changing the width of the window also changes the height of the window to match, and changing the height changes the scale of the game view.

  • When you have a free/unconstrained aspect, changing the width of the window does not change the height of the window. Because the height of the window stays the same, the scale of your game view also stays the same.

Note that this is only a change in the projection mapping between the game world and the screen pixels. Your world itself - from the perspective of your code or any entities living in the game world - is still the same size. Mario doesn't have to work harder to jump higher when you play on a 1080p screen instead of 240p. We've just scaled the rendered output to cover more screen pixels.

That's why the text option AutoSize doesn't do anything when you change the window size. Its job is to fit the point size of the text to the world size of the text box. Because changing your view does not alter the underlying world, that text box still has exactly the same dimensions inside the game world, and there's no change for AutoSize to adapt to.

If you'd like to customize the scaling behaviour, you can do that with a script.

You can also get a variety of easy-to-use scaling modes if you use the UI system (so, a Canvas object with Image and TextMeshProUGUI children, not SpriteRenderer and TextMeshPro). This system is designed to support flexible layouts to adapt to different screen resolutions, with lots of configuration options to control exactly how you want your layout to adapt.

\$\endgroup\$
2
  • \$\begingroup\$ Thanks, this is clearer now. So, suppose I want to know, during development, how my game would look like on different screens. What option should I use: the Free Aspect or the Fixed Aspect? \$\endgroup\$ Nov 4 '21 at 10:51
  • \$\begingroup\$ If you plan to support one fixed aspect ratio, use that fixed aspect. If you plan to support displays with different aspect ratios, use free, and periodically drag your game window to different shapes/sizes to see how it adapts. If you have a small list of specific resolutions you want to support (eg. specific phone models) then periodically cycle through those fixed resolutions. \$\endgroup\$
    – DMGregory
    Nov 4 '21 at 11:35

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .