Search Unity

TextMesh Pro Monospacing gone crazy in builds

Discussion in 'UGUI & TextMesh Pro' started by LilGames, Sep 17, 2020.

  1. LilGames

    LilGames

    Joined:
    Mar 30, 2015
    Posts:
    568
    I previously stuck to plain vanilla TMP text fields and disabled Rich Text. No issues. TMP is great!! I then discovered the monospacing option by enabling Rich Text and using the <mspace> tag. GREAT! makes scores and timers look better.

    Here's how my timer and score look like in Unity Editor and Unity Play mode, using <mspace=2.75em> :

    tmp_in-unity_monospaced.jpg

    Here it is in Builds for Windows 64 bit as well as Android APK!

    tmp_in-builds_monospaced.jpg

    What's going on? Do I need to regenerate my fonts or something?

    Unity 2018.4.1f1
    Text Mesh Pro 1.3.0 (verified for 2018.4)
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Does your text use Auto-Size? If so then using something like a Canvas Scaler which would result in the point size changing would have an affect on this.

    There were issues related to how character spacing was affected by point size in previous version of TMP which were eventually addressed in version 1.5.x release cycle. These changes were made to ensure all spacing adjustment including <mspace> were consistent where the value represents 1 / 100 em where 1 em is equal to the point size of the text.

    Please be sure to test with the latest release of TMP which is version 1.5.1 for Unity 2018.4. The character spacing could be different due to the changes / fix affecting all spacing but once you adjust the spacing value, it should remain consistent regardless of point size / scaling.

    Let me know if the issue persists after upgrading to the latest release of the TMP package.
     
  3. LilGames

    LilGames

    Joined:
    Mar 30, 2015
    Posts:
    568
    The reason I had not tried the obvious and updated is that no versions of TMP other than 1.3.0 are indicated as "Verified". But now after your advice, I've updated. The result is an error in TMP itself:

    Library\PackageCache\com.unity.textmeshpro@1.5.1\Scripts\Editor\TMPro_FontAssetCreatorWindow.cs(11,19): error CS0234: The type or namespace name 'TextCore' does not exist in the namespace 'UnityEditor' (are you missing an assembly reference?)

    So.... now what?
    Tried 1.5.0 Same error.
     
    Last edited: Sep 19, 2020
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The above errors appears to be some Library cache error. Please delete the package cache from within the Library folder.
     
  5. LilGames

    LilGames

    Joined:
    Mar 30, 2015
    Posts:
    568
    I've updated Unity to 2018.4.27f1 and now it's all good!
    Thank you for your assistance and a great text solution!
     
    Stephan_B likes this.
  6. LilGames

    LilGames

    Joined:
    Mar 30, 2015
    Posts:
    568
    @Stephan_B Is it possible to change the "width" configuration of a specific character? For example, it's great that digits are all the same width now, but the comma and decimal point has too much horizontal spacing.
     
  7. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    It is possible to adjust the Advance (AX) value of individual glyphs in the glyph table of the font asset but monospace overrides this value to make it the same for all glyphs which is what you normally have with monospace fonts.
     
  8. LilGames

    LilGames

    Joined:
    Mar 30, 2015
    Posts:
    568
    Makes sense. So to get what I want, I'd have to NOT use monospacing, and I guess manually edit the glyph definitions to have digits all the same width, is this possible? (I see "m_Width:" definition in the SDF asset file)
     
  9. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    You could either use a Monospace font or edit the metrics of individual glyphs.

    The glyph metrics that would need potential editing are Bearing X (BX) and Advance (AD).

    Monospace fonts typically have identical glyph advance values. The bearing values can be different as the related to the positioning of the glyphs relative to their origin but not spacing between glyphs which is what Advance is.

    Note:
    The GlyphRect values represent the position of the glyph in the Atlas Texture.

    The GlyphMetrics values are as follows:
    Width (W) and Height (H) are the actual width and height of the glyph in the Atlas Texture. These should not be changed unless you modify the glyph image in the Atlas Texture.
    The Bearing X (BX) and Bearing Y (BY) represent the offset applied to the Origin (pen drawing position) of the current glyph.
    The Advance is the positional offset from the origin of the glyph. The Advance position becomes the Origin of the subsequent glyph.
     
    LilGames likes this.