Search Unity

TextMesh Pro Text size is being reset when setting TMP_Text.text to null

Discussion in 'UGUI & TextMesh Pro' started by JoshRickert, Mar 23, 2018.

  1. JoshRickert

    JoshRickert

    Joined:
    Feb 28, 2017
    Posts:
    4
    I'm on Unity 2017.3.1f1 and TextMeshPro-2017.3-1.0.56.

    I have a text object with the font size set to 18. When I assign my TMP_Text instance's `text` property to `null`, the font size gets reset to 36. This doesn't happen if I try to clear that field by assigning an empty string.
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I'll take a look and provide an update once I have more information.

    Out of curiosity, any reason you are setting the text property to null instead of string.Empty?
     
  3. JoshRickert

    JoshRickert

    Joined:
    Feb 28, 2017
    Posts:
    4
    Thanks for the quick response, Stephan.

    No, there's no reason it had to be done that way. I just couldn't locate a clear answer in the documentation for how to correctly clear the text field.
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    You should be using string.Empty to clear the text.

    The reason why the point size resets when setting the text to null is because in Awake the object thinks if was just newly created so the default settings are reapplied to it.

    BTW: What are the steps to reproduce the behavior you reported?
     
    Last edited: Mar 23, 2018
  5. JoshRickert

    JoshRickert

    Joined:
    Feb 28, 2017
    Posts:
    4
    string.Empty
    solved the issue for me. I tried to build an isolated test case for you but I can't seem to duplicate the issue right now.

    The bad assignment was happening in a parent object's
    OnEnable
    while being retrieved from a pool. Not sure if that's relevant but sharing just in case.

    Thanks for the help!
     
    Stephan_B likes this.
  6. korober

    korober

    Joined:
    Jan 20, 2015
    Posts:
    16
    I've got same issue now. Thanks for the answer. But this is not clear behaviour :( It's good idea to add the info to official docs (text property and SetText method).