Search Unity

TextMesh Pro TextMesh Pro UGUI margins

Discussion in 'UGUI & TextMesh Pro' started by kabumere, Nov 4, 2017.

  1. kabumere

    kabumere

    Joined:
    Oct 2, 2016
    Posts:
    31
    Before I get into my question regarding margins, I have a pre-question, if you will:

    Can someone explain (or point to documentation regarding) what the TextMesh Pro shader does? I left on the default: TextMesh Pro/Mobile/Distance Field. It seems at first that it just shows/hides different settings you can apply to your text, depending on which shader you choose. But I'm sure there's more to it.

    Now for the actual question: Is there a way to apply a margin to my text? At first I was going to just set the X and Y of the Text's Rect Transform to include the extra space I want. But I figured including it on the TMP UGUI object itself would allow it to be more consistent across device sizes. I saw an old video where it said Margins were being added, but it was a feature still in beta at the time (it was over 3 years old), so I figured I'd ask for updated info.

    Also in the video, the available options were different for the TMP UGUI object than what I see for mine. I don't know if that's due to the video being so outdated, or if I'm hiding options by choosing the wrong shader (hence my pre-question).
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    The ability to dynamically style the visual appearance of text objects by adding things like Dilation, Outline, Shadow, etc comes from the use of Signed Distance Field combined with the custom shaders included with TextMesh Pro. There are several posts and videos on the TextMesh Pro user forum explaining the difference between the shaders. Here is one such post.

    Besides the Yellow Margin controls around the RectTransform which are exposed in the Extra Settings Panel of the text object inspector, you can also use the <Margin> tag in TextMesh Pro. See the following documentation. You should also take a look at example "09 - Margin Tag Example" includes with TextMesh Pro as it covers this feature as well.

    Speaking of examples, I would suggest going thru each of the example scenes includes with TextMesh Pro as they cover some of the core functionality of the tool.
     
  3. kabumere

    kabumere

    Joined:
    Oct 2, 2016
    Posts:
    31
    Thank you for that. Read the forum post and looking into the example scenes now. Regarding performance: I see you said the Mobile shaders offer best performance due to having a reduced feature set. I'm assuming however, that's relative to the desktop shaders and not to Unity's built in Text UI object.

    So do you recommend using TMP UGUI Text for all text objects in game, even ones requiring no textures or lighting, or should we only use TMP for texts requiring some sort of visual change, and Unity UI for all others for best performance?

    EDIT: It seems there is no vertical margin, right? So left and right use the respective margin tags, but for vertical spacing just move the rect transform itself down.
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    The shader comparison is between the TextMesh Pro shaders themselves.

    Having said that, if you were to compare the overall performance between UI.Text and TextMesh Pro when displaying plain white text, you would notice that TMP's performance either equals or is slightly better then UI.Text. However, if you were to add an outline or shadow to this text object using a material preset in TextMesh Pro vs. using the UI - Effect - Outline or Shadow, depending on the device, you would notice that TMP's performance would be between 5x and 10x better. Here is a link to a post a made about this a good while back.

    There is no top or bottom margin controls other than the text container margin controls (yellow lines) which I described before.
     
  5. chrust33

    chrust33

    Joined:
    Dec 1, 2016
    Posts:
    3
    Hi!
    Is there a way to set margins values (yellow lines) by code?
     
  6. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,596
    Yes.

    Code (csharp):
    1.  
    2. /// <summary>
    3. /// The margins of the text object.
    4. /// </summary>
    5. public virtual Vector4 margin
    6.  
    The order is Left, Right, Top, Bottom
     
    helgrind21 likes this.
  7. chrust33

    chrust33

    Joined:
    Dec 1, 2016
    Posts:
    3
    Thank you!
     
  8. Andrew-Garrison

    Andrew-Garrison

    Joined:
    Oct 3, 2012
    Posts:
    19
    For anyone else stumbling across this post, it appears margin is actually: Left, Top, Right, Bottom
     
    zhenhaoze likes this.