Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question TextMeshPro character index in parsed vs unparsed text

Discussion in 'UGUI & TextMesh Pro' started by Novack, Oct 26, 2023.

  1. Novack


    Oct 28, 2009
    Hello. I was looking into some way to go from TMP_WordInfo.firstCharacterIndex to its equivalent on the unparsed text.
    Code (CSharp):
    1. TMP_WordInfo wordInfo = textMeshProUGUI.textInfo.wordInfo[n];
    2. int indexInText = textMeshProUGUI.textInfo.characterInfo[wordInfo.firstCharacterIndex].index
    I found the above works for getting the index of a character in the text, as long as the text does not include any rich text tags on it. Otherwise, the indices are incorrect, as TMP_WordInfo.firstCharacterIndex does not consider the tags.

    However, I dont seem to find the right api methods for this, does someone knows the proper solution?

    At the moment, Im finding the index by hand, by looping through the raw text string, but I was wondering if given we have an index already, maybe there is a way to convert it to its unparsed equivalent.
    Last edited: Oct 27, 2023