Search Unity

TextMesh Pro GetParsedText() gives a string of empty characters.

Discussion in 'UGUI & TextMesh Pro' started by Ganosal, Apr 24, 2017.

  1. Ganosal

    Ganosal

    Joined:
    Sep 25, 2015
    Posts:
    6
    I have been trying to use TMP_Text.GetParsedText(), but the string I get exists out of empty characters (while the length of the string is correct).
    So by example when I have the text "<#ffffff>Test" the resulting string will just be "" and has a length of 4.

    Am I doing something wrong or is this a bug?

    The version of Unity I use is: 5.5.0.f3 and TextMesh Pro is version: 1.0.55.0b8.


    Edit: I just found out that you have to wait a frame or use ForceMeshUpdate() to make the text work. So consider this problem solved.
     
    Last edited: Apr 24, 2017
    PoRtCuLLiS likes this.
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Since the text is processed / generated just before the frame is rendered (when a change has occurred), the resulting change won't be reflected or the textInfo data structure updated until this has happened. Most of the time this is fine but for those times when you need to text to be processed right away, you can use the ForceMeshUpdate() function as you have stated in your edit :)
     
    PoRtCuLLiS likes this.
  3. visca_c

    visca_c

    Joined:
    Apr 7, 2014
    Posts:
    30
    Hello, I noticed GetParsedText() would always include a zero-width white space character as the last character, is this by design?
     
  4. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    When working with the input field, you should not be accessing the text of the child text component. This component is used to display the text. Instead you should be accessing the parent input field .text property.

    As for the reason, imaging an input field set for password. The text of the child component would be "*****" whereas the text of the parent input field would contain the actual password.
     
  5. visca_c

    visca_c

    Joined:
    Apr 7, 2014
    Posts:
    30
    I needed to access the displayed text without rich text tags, is there another way to properly access it?
     
    PhannGor likes this.
  6. ritesh_khokhani

    ritesh_khokhani

    Joined:
    Jun 26, 2013
    Posts:
    47