Monospacing gone crazy in builds

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 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> :

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

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)

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 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.

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.

The above errors appears to be some Library cache error. Please delete the package cache from within the Library folder.

I’ve updated Unity to 2018.4.27f1 and now it’s all good!
Thank you for your assistance and a great text solution!

1 Like

@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.

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.

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)

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.

1 Like