Canvas ratio issues when building to Android?

I’ve attached 2 screenshots, the build in the Editor and the build running on my phone (Nexus 4) - I’ve tried a few things, but I can’t get the scale right. The left/right anchors also aren’t pulling all the way to the left or right of the screen, there’s very large open spaces on anchored items (not in screenshot, screenshot is anchor center).

1747732--110421--Editor15x10.JPG

AFAIK that’s because GUI by default keeps size of GUI elements same for elements pixel-wise, not relative-screen-size-wise. That means that with bigger resolution, your elements will take relatively less space.

How to solve this? There are two components which you can use in Unity GUI (if you use one, don’t use the other at the same time!) (attach on game object with Canvas):

  • Reference Resolution - you configure reference resolution, which is the one you’re working with and when the real resolution is different, GUI will be scaled so the relative size of the GUI to the screen will be still same. If you’re for the simplest and fastest solution, I would recommend this.
  • Physical Resolution - you select a unit (like milimeters) and then all elements size will be in this unit, not in pixels. This will make GUI elements to have same physical size across your devices. That means, that with physically (not pixel-wise) bigger screen you will have more size (space around your GUI).

With both solutions are some problems, especially if you want to support both horizontal and vertical orientation on Android devices (if you want support only one, then there is no problem with Reference Resolution). More details about the problems in my post: Resolution and scaling - screen, font and sliced image problems. - Unity Engine - Unity Discussions

Note: I don’t know whether you’re aware of this, but you can change size of screen in editor and test how you GUI acts with different screen sizes.

3 Likes

The shot in the editor had my custom 15:10 size (for my Nexus 4) :slight_smile:

Thanks for the tip! I wouldn’t of found the magic “make it work” components otherwise! With that component added it now 100% looks on my device like it does with my simulated aspect ratio in the Editor.

… that said - I’ve been using Unity for a couple years now, I was really, really surprised that my simulated aspect ratio in the editor did not correspond to my device in any way with these new feature, I’m pretty used to my editor space simulating aspect ratios looking like what they should look like on device. If the whole point is being able to build games for multiple platforms then ignoring the fact multiple platforms (by default) have multiple pixel densities sounds like a bad idea. The behavior of that magic-script should probably be defaulted with uGUI.