Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Bug TMP Monospace Tag Issue

Discussion in 'UGUI & TextMesh Pro' started by TomTheMan59, May 16, 2022.

  1. TomTheMan59

    TomTheMan59

    Joined:
    Mar 8, 2021
    Posts:
    156
    Is this a known issue? The monospace isn't making the spacing between these characters even.

     
  2. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,582
    Monospacing doesn't make the spacing between characters even, if makes the spacing of each character even.

    Below is an example where I am using "<mspace=20>0.00" where it doesn't seem like the characters are evenly spaced.

    upload_2022-5-17_12-59-51.png

    However, if I draw rectangles of identical size around each character, we can see they are in fact correctly and evenly spaced.

    upload_2022-5-17_13-4-42.png

    Note that each character is centered in the given space which in this example is 20 units.
     
  3. TomTheMan59

    TomTheMan59

    Joined:
    Mar 8, 2021
    Posts:
    156
    Dang! I am trying to get my timer to stop jiggling and someone suggested doing this.

    Is there anyway to stop the font from jiggling as it counts up? It isn't a monospaced font and the only solution is to set it to align upper-left but that doesn't keep it centered in its container.

    I tried centering the text every frame by measuring its length, but that also causes jiggling.

    Another solution was to break up the seconds and milliseconds into two different labels but that doesn't work as the period can be overlapped.

    Is there anyway to fix this issue easily?
     
  4. TomTheMan59

    TomTheMan59

    Joined:
    Mar 8, 2021
    Posts:
    156
  5. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,582
    Using the <mspace=x> markup tag should work.
     
  6. TomTheMan59

    TomTheMan59

    Joined:
    Mar 8, 2021
    Posts:
    156
    This is what I did in the OP and you explained why it doesn’t work. I am very confused :(?

    You can see the spacing between the period is the issue.
     
  7. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,582
    When using Monospace and depending on the font, the spacing can look weird but you should be able to tweak the <mspace=x> value to get a decent result and when doing so, the digits / glyphs will be stable.
     
  8. Prodigga

    Prodigga

    Joined:
    Apr 13, 2011
    Posts:
    1,094
  9. Stephan_B

    Stephan_B

    Unity Technologies

    Joined:
    Feb 26, 2017
    Posts:
    6,582
  10. Prodigga

    Prodigga

    Joined:
    Apr 13, 2011
    Posts:
    1,094
    Thanks for chasing up!

    In the example above it was single UGUI TMP component with a portion surrounded by tags. ie:
    Code (CSharp):
    1. <mspace=0.65em>1.23</mspace> miles
    But I've since split it up into two separate UGUI TMP objects (positioned using a horizontal layout group) and swapped out for a true monospace font. The true monospace font works fine, and the old font still doesnt work. So, to be clear, this is two separate TMP components:
    • One just says 'Miles' (no mspace tags)
    • the other one is the number and the entire thing is surrounded by mspace tag
    https://imgur.com/a/6aN0GAP