Search Unity

TextMesh Pro Dynamic margins hardcoded?

Discussion in 'UGUI & TextMesh Pro' started by J_P_, Apr 27, 2018.

  1. J_P_

    J_P_

    Joined:
    Jan 9, 2010
    Posts:
    1,027


    White text is Unity's text and I want that positioning. Gray text is TextMesh Pro and even though margins are set to 0 and both have alignment set to left/bottom, you see the gray text is farther from the bounding box. If the font size is reduced, it gets closer to the edges. Oddly, if I set to top alignment, it goes down some (but not all the way).



    Same behavior with the built in font assets so I don't think it's my custom one causing issues. Same behavior whether I use Auto Size or change size manually. Am I missing something (I'm new to TextMesh Pro)?

    I'm in 5.6.2f1 and the asset store gave me TextMesh Pro 1.0.54.

    I'm trying to use TextMesh Pro because on iPad 3, that large text (set to "best fit") literally takes several seconds to update when using Unity's ugui Text...
     
    Last edited: Apr 27, 2018
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    There are several things that could affect the alignment of the text. The font asset, its metrics like Ascender, Baseline and Descender and the margins. Unfortunately, the images above don't provide enough information to know what exactly is contributing to the result you are showing above.

    Included in the example scripts provided with TextMesh Pro is a script named "TMP_TextInfoDebugTool.cs", add this script to this Bob text object. Then enable Show Characters as per the image below.

    upload_2018-4-27_0-10-40.png

    This tool will allow you to visualize the bounds of characters (yellow box), Ascender, Cap Height, Baseline and Descender (blue lines) of each characters. So when using bottom alignment, the bottom blue line (Descender) should be aligned with the bottom of the RectTransform / margin in case it was changed. Margins can be seen in the Extra Settings.

    Here is an image using the word BOB but with Futura Bold (I don't have Futura but the metrics should be similar).

    upload_2018-4-27_0-14-23.png

    Left with object selected where the Descender is hidden behind the yellow margin line. Right un-selected where you can see the alignment is correct.

    Now we just need to figure out why in your case you are not getting the correct results.

    P.S. The version of TMP for Unity 5.6 should 1.0.56 so 1.0.54 seems wrong. See the following thread which includes direct links to download TMP.
     
  3. J_P_

    J_P_

    Joined:
    Jan 9, 2010
    Posts:
    1,027
    Screen Shot 2018-04-27 at 11.26.51 AM.png

    Debug lines shown, but I might have found a clue -- with the Unity text, I had "Align by Geometry" checked and unchecking it brings it closer to TextMesh Pro. I can't find a similar option in TextMesh Pro

    edit: I might have had 1.0.56 already -- the user guide has 1.0.54 listed and that's what I went by. Either way I have 1.0.56 now.

    edit2:
    bobgif.gif

    You can see how "Align by Geometry" changes how Unity text (white) scales. I'm also not sure what those semi-transparent boxes are when TextMesh Pro text gets smaller... edit3: the boxes fade in as the text is smaller relative to camera -- fades out when you zoom in. Not sure if it's like that outside the editor.

    edit4: boxes go away if I make atlas resolution a smaller size
     
    Last edited: Apr 27, 2018
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    TextMesh Pro does not offer an align by geometry vertical option simply because as soon as you type a letter with a descender such as a lowercase "p" or "j", it would cause all other letters to move up which is bad. Instead if you need the text to be closer to the bottom RectTransform, you can either use the margin or adjust the Descender of that font asset.

    In terms of the ghostly image, that is simply due to the Ratio of Sampling Point Size to Padding being to small for the material property values being used. See FAQ Question 2 and 11.
     
  5. J_P_

    J_P_

    Joined:
    Jan 9, 2010
    Posts:
    1,027
    I'm using all caps, so no descenders. Margins in TextMesh Pro still scale with text size, so I'll have to dynamically set margins after updating the text -- would be nice if that were a feature (would essentially mimic Align By Geometry w/o descenders popping up text).

    The left margin seems to be based on the first character (see B vs T), but I can probably live with that

    edit: I got it fixing the margin after changing text, though there's a single frame where it's wrong because I can't read the new fontSize until waiting a frame. There a workaround for that? Not a big deal for this project but would be good to know for future ref since I'm considering moving everything over to TMPro.
     
    Last edited: Apr 27, 2018
  6. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Text alignment is based on font metrics which on the left is Origin, right Advance, top Ascender and bottom Descender.

    If you adjust the Descender of the font asset you are using in the Font Asset Inspector to the same position as the Baseline which is typically zero, you will get the positioning you seek at all point sizes.
     
    J_P_ likes this.
  7. J_P_

    J_P_

    Joined:
    Jan 9, 2010
    Posts:
    1,027
    Yep, that works -- thanks for all your help and patience!
     
  8. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    You are most welcome.

    When I have time, I'll look at adding the vertical alignment based on geometry.