Search Unity

Font size on mobile

Discussion in 'UGUI & TextMesh Pro' started by RogueCode, Aug 22, 2014.

  1. RogueCode

    RogueCode

    Joined:
    Apr 3, 2013
    Posts:
    230
    I've started playing with the new UI stuff and have a small problem.
    In the editor my text elements are perfectly sized (I've selected the correct Windows Phone resolution in the previewer). But when I deploy to an actual device the font is all really tiny.
    To get it to be the correct size on my Lumia 1520 I need to set the font size really big, which then makes it unreadable on PC.
    All the rest of the UI is displayed correctly.

    Thanks!
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    Are you testing at the same resolution in editor as the device? Related, does using a Reference Resolution component have any effect?
     
  3. RogueCode

    RogueCode

    Joined:
    Apr 3, 2013
    Posts:
    230
    Yup, I'm using the correct resolution. Switching between all the available resolutions in the editor shows it pretty much the same size in all of them. And deploying to a range of Windows Phones I have from 800x480 to 1920x1080 all have the text consistently small.


    I'm not sure what the Reference Resolution component is (searching didn't lead me to anything specific).
     
  4. TheRobWatling

    TheRobWatling

    Joined:
    Feb 18, 2013
    Posts:
    45
    Did you try using the Best Fit option on the Text? It seems to work for my Android build.
    EDIT: The Reference Resolution script is a component you add to the Canvas and set the specific resolution.
     
  5. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    Well, it's more accurate to say that RR makes the UI simulate a particular resolution.

    Best Fit is an option that's best used sparingly - it is a performance hog, as in order to find the best fit, the text component has to try a bunch of different ones until it finds the right one. Besides that, having the engine setting every button's text size slightly differently based on content will surely make your graphic design guy twitch uncontrollably. It might be a passable temporary workaround, but not a solution.
     
  6. RogueCode

    RogueCode

    Joined:
    Apr 3, 2013
    Posts:
    230
    Ah, so I figured out a really stupid mistake. My PC resolution is lower than my phone, and Unity was downscaling the preview.
    This means I'm now seeing it correctly in the preview window as it shows on my device.

    So I guess my question is: Why does text not scale with the resolution?
    Without using Best Fit (which seems like a terrible solution), is there a way to make the text roughly get bigger as the resolution gets higher? As it is currently I'd have to detect the resolution and change the font size in code, else really low resolution phones will get text flowing over the borders, while high resolution devices will have the text being tiny in their border.
     
  7. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    Use Reference Resolution. This is exactly what it's for.
     
    RogueCode likes this.
  8. rakkarage

    rakkarage

    Joined:
    Feb 3, 2014
    Posts:
    683
    file:///C:/Program%20Files%20(x86)/Unity/Data/Documentation/html/en/Manual/HOWTO-UIMultiResolution.html
     
    RogueCode likes this.
  9. RogueCode

    RogueCode

    Joined:
    Apr 3, 2013
    Posts:
    230
    Ah, thanks for the docs, got it working now! :D