Strange View When Resizing Game's Window?

Hi,

Moving along…
When we resize the game’s window to a dimension smaller than declared x,y size
we get a truncated canvas in the smaller game window?

Please see screenshot below of the issue:
Any ideas?
Thanks!

Jesse

I suggest you start by reading this:
Designing UI for Multiple Resolutions (Unity Manual)

If that’s not enough information to get the effect you want, then come back and explain what you want your game to do instead.

What we need is the following:
Fixed resolution of 360x640 with game canvas scaling and maintaining aspect ratio on window resizing…

Fixed resolution is the opposite of scaling, so requesting both is contradictory. And your pictured example does maintain the aspect ratio of your content.

Computers are like evil genies: they’ll grant your wishes, but you’d better phrase your wishes perfectly, because they’re going to give you exactly what you asked for and not what you imagined in your head. A “do what I mean” instruction would be handy but does not exist.

It looks like what your game is currently set up to do is to scale your content proportionately in both dimensions so that the height of your content matches the height of the window. This preserves your aspect ratio and uses all available height, but the width of your content could be different from the window (because you can’t match height, match width, and preserve aspect ratio all at the same time).

The most common strategies for coping with a window size that isn’t your preferred aspect ratio are:

  • Stretch: Scale your width and height independently so that each matches the window size (your content will be distorted because aspect ratio is not preserved)
  • Letterbox: Scale your content proportionately to fit the tighter of width or height, leaving some empty/unused space on the other axis
  • Zoom: Scale your content proportionately to fit the looser of width or height, causing some of your content on the other axis to extend outside the bounds of the window. Either crop that extra content or enable scrolling.
  • Forbid: Control the window size from code and don’t allow the user to change the aspect ratio in the first place.

More sophisticated software can combine different strategies for different parts of the UI so that the overall layout changes to use the available space more efficiently. For instance, you could make the buttons stretch horizontally to fill the available space but keep the text labels unstretched so that they don’t look distorted.

I suspect you are imagining letterbox. AFAIK Unity does not have an option specifically designed to letterbox your entire game (which is weird, because the game view inside the editor already does this, so they clearly wrote code to do it).

You can use an AspectRatioFitter with its mode set to “fit in parent” to get a game object of the appropriate size and shape, but that works by adjusting the object’s width and height, not its scale, so content inside of it won’t automatically get bigger/smaller unless its anchors are set to scale, and setting up all your anchors that way is usually a giant pain. Also, I’ve heard that “fit in parent” mode is not very efficient.

However, you could pretty easily write your own component that checks the width and height of its parent (or of the whole screen) and then applies a scaling factor to itself to fit within those bounds. If that’s precisely what you want.