Search Unity

What is the default line spacing value?

Discussion in 'UGUI & TextMesh Pro' started by owen_proto, Jun 22, 2020.

  1. owen_proto

    owen_proto

    Joined:
    Mar 18, 2018
    Posts:
    120
    TextMeshProUGUI.lineSpacing is a public field to define extra line spacing for the text. What is the recommended way to access the value of the line spacing that is applied by default (before lineSpacing is added)?
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The line spacing is defined in the font asset in the Face Info. This is typically

    LineSpacing = Ascender - Descender + LineGap

    Line gap is the difference between LineSpacing and Ascender - Descender.

    Having said that, the lineSpacing property simply adds more spacing to the value defined in the font asset. This also corresponds to the line spacing in the text object component inspector.
     
    owen_proto likes this.
  3. owen_proto

    owen_proto

    Joined:
    Mar 18, 2018
    Posts:
    120
    I thought LineGap was what I was looking for, but it seems not. When text automatically wraps, extra spacing between lines seems to be added. Pictured below are several text objects that have been lined up in a custom vertical layout group. The layout group isn't adding any extra spacing between the text objects, but there is a noticeably taller gap between the lines of the wrapped text objects. I'm not sure where the setting is for this gap. I'd like to control/read it via script.
    Screen Shot 2020-06-30 at 1.16.53 PM.png Screen Shot 2020-06-30 at 1.38.09 PM.png
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Are these text objects all using the same font asset?

    You can visualize this line spacing and text metrics by adding the TMP_TextInfoDebugTool.cs script found in the TMP Examples & Extras to these text objects. This will allow you to see the Ascent and Descent lines which might help you understand where the extra spacing is coming from.

    Please consider using Preview 14 of the TMP package and to upgrade to the non preview release when it is available later this week / over the weekend.
     
    owen_proto likes this.
  5. owen_proto

    owen_proto

    Joined:
    Mar 18, 2018
    Posts:
    120
    Thanks for the quick reply. That debug tool is tremendously helpful! It helped me discover my issue, which turned out to simply be that I wasn't taking ascender and descender values into account in a different place in my script. Doh! Thank you!