Search Unity

TextMesh Pro Problem with GetTextInfo(string text)

Discussion in 'UGUI & TextMesh Pro' started by TheValar, Mar 15, 2019.

  1. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    760
    I find myself needing the eventual text info of a TextMeshProUGUI component for content that has not yet been assigned to it. When I saw the GetTextInfo function that took a string as a parameter I assumed this was the tool for the job. After trying it out it seems to just return a text info object with default values. Am I misunderstanding what this function is supposed to do or is there a bug with it?

    thanks :)
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    I am not sure about the state of that function.

    Can you provide more insight on your use case and what specific information you want to get out of the textInfo?
     
  3. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    760
    Sure thing. Basically I'm setting up a dotween sequence to animate the text in character by character using maxVisibleCharacters. so I need to iterate all of the visible characters in the text excluding all rich text tag type content. So basically I'm just trying to get all the characters that the user will see post rich text processing
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    The easiest way to handle this is to use set the text property as you normally would on the text object and then ForceMeshUpdate() to get the text object and textInfo updated right away.

    Then simply iterate over the characterInfo[] using texInfo.characterCount and filtering out characters that are not visible which is also contained in the characterInfo[].

    textInfo.characterInfo[] only contains displayable characters (visible and non-visible but no tags).

    Look at scripts used in the TMP Examples & Extras like Animating Vertex Attributes and VertexJitter.cs and others.

    Here is another example which might prove useful to look at.
     
  5. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    760
    Unfortunately I need to access this information prior to actually rendering the text because there will still be old text present that needs to be faded out. I suppose for now I will have a hidden text field with the same parameters and set the text value on it for the calculation.