Search Unity

Canvas ratio issues when building to Android?

Discussion in 'UGUI & TextMesh Pro' started by Renih, Aug 25, 2014.

  1. Renih

    Renih

    Joined:
    Jan 22, 2013
    Posts:
    6
    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).
     

    Attached Files:

  2. Aithoneku

    Aithoneku

    Joined:
    Dec 16, 2013
    Posts:
    67
    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: http://forum.unity3d.com/threads/re...screen-font-and-sliced-image-problems.264035/

    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.
     
    SausageOG, Tim-C and thempus like this.
  3. Renih

    Renih

    Joined:
    Jan 22, 2013
    Posts:
    6
    The shot in the editor had my custom 15:10 size (for my Nexus 4) :)

    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.