Search Unity

TextMesh Pro Accessing custom style from CharacterInfo

Discussion in 'UGUI & TextMesh Pro' started by TheValar, Feb 11, 2019.

  1. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    760
    Is there any way to determine if a custom style tag is affecting a particular character?

    I'm hoping to find a way of applying vertex animations to specific characters in a text object and custom styles seems like it would be a nice way to achieve this.
     
  2. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    If I understand correctly, you would want to use the style tag to define a region of text that would could identify and then modify / animate afterwards. Correct?

    Instead of using the style tag, the <link="ID"> </link> should work as you could then query the textInfo.linkCount and textInfo.linkInfo[index] to know the first character and length and then use that information to iterate over those characters in the textInfo.characterInfo[index] to modify their vertex attributes.

    P.S. The link tag is just a way to identify sections of the text. The link ID doesn't have to be unique per link. So if you have several types of animation they animation type would have a unique link ID but this ID could be found multiple times in the text itself.
     
  3. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    760
    That sounds like just what I need. I suppose I could even encode animation parameters into the link ID string that I could parse out on the other end. And of course I could still wrap that link tag in a style tag for convenience. Thanks a bunch :)
     
    Stephan_B likes this.
  4. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    760
    Ok I've tried this out today and it's working pretty well. The only caveat is that when I update the text of the TextMeshProUGUI component the TMP_LinkInfo from the previous text content is retained so I have to manually clear it whenever I change the text
     
  5. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    A lot of the data structures (Arrays) used in textInfo are not cleared (for performance reasons) but the textInfo itself in terms of linkCount, etc. should accurately reflect the number of valid links.

    One important aspect to be aware of is the textInfo and substructures do not get updated until the text object has been processes which happens late in the update cycle and just before the frame is rendered. So when changing the text and immediately querying this data, it would not be reflective of the recent changes. For that and when you need to access the updated data right away, you can use TM_Text.ForceMeshUpdate() which will force the text object to be process right away and the textInfo populated accordingly.
     
  6. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    760
    I guess there is a bug in that case. I am calling ForceMeshUpdate() before accessing the link info and those links never go away even in subsequent frames. I have to TM_Text.textInfo.linkInfo = new TMP_LinkInfo[0]

    I will see if I can get a simple repro project going for you
     
  7. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    That would be great.
     
  8. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    760
    Looking into this a tad more it seems that although the actual link info never gets cleared, and therefore linkInfo.Length will still be greater than 0 if I check textInfo.linkCount it has a value of 0 as desired. Looking back at your past message you did say "linkCount" specifically so I'm now thinking this is intended behavior.

    Is that correct?
     
  9. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Correct. The data in the Arrays gets overwritten / replaced by updated data when necessary. So as long as you iterate over the textInfo count of whatever sub structure you are working with, you should be fine.

    Also note these arrays are allocated in blocks so the array size is rarely representative of the number of whatever you are trying to iterate over.
     
  10. TheValar

    TheValar

    Joined:
    Nov 12, 2012
    Posts:
    760
    I've redone a bit of my code to respect this information and all is working wonderfully. Thanks for all the help I truly appreciate how active and quick you are on these forums
     
  11. Stephan_B

    Stephan_B

    Joined:
    Feb 26, 2017
    Posts:
    6,595
    Glad it is working and you are most welcome :)