Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Bug TextMeshPro: lastCharacterIndex works inconsistently or not at all.

Discussion in 'UGUI & TextMesh Pro' started by aaversa, Feb 7, 2021.

  1. aaversa

    aaversa

    Joined:
    Sep 5, 2016
    Posts:
    41
    I have a simple scene with nothing but a TextMeshProUGUI on a canvas. A script sets the text to something like "Hello World" on Start(). I then use a simple script to check some text info:


    Code (CSharp):
    1.             Debug.Log("Input text is: " + tmpObject.textInfo.textComponent.text);
    2.             Debug.Log("Total character count is: " + tmpObject.textInfo.characterCount);
    3.             Debug.Log("Current page is " + tmpObject.pageToDisplay);
    4.             Debug.Log("Total page count is " + tmpObject.textInfo.pageCount + ", array size is " + tmpObject.textInfo.pageInfo.Length);
    5.             Debug.Log("Last character index on current page is " + tmpObject.textInfo.pageInfo[tmpObject.pageToDisplay].lastCharacterIndex);
    6.             for (int i = 0; i < tmpObject.textInfo.pageInfo.Length; i++)
    7.             {
    8.                 TDebug.Log("Last char index on page " + i + " is: " + tmpObject.textInfo.pageInfo[i].lastCharacterIndex);
    9.             }
    The input text is read correctly. The total character count is also correct. But the "lastCharacterIndex" is 0, not just for the current page, but for every page in the area. I cannot get lastCharacterIndex to display anything other than 0.

    In another scene - which is much more complex - this same exact code appears to work, with lastCharacterIndex correctly displaying the last character for the given page (I sometimes use multi-page text.)

    However, in that scene, adding a dash as the very last character to a line of text causes lastCharacterIndex to always return 0. 100% of the time. Removing the dash but changing nothing else makes the code work just fine.

    This is with Unity 2020 and the latest version of TMP.