the PageInfo is not updated after ForceMeshUpdate is called, my workaround is waiting for one frame.
the PageInfo[page].lastCharacter is wrong when the text is end of “\n” (maybe the same on other escape characters ), for instance
text: “This is a test string”
textInfo,characterCount: 21
pageInfo.firstCharacterIndex: 0
pageInfo.lastCharacterIndex: 20
text: “This is a test string\n”
textInfo,characterCount: 22
pageInfo.firstCharacterIndex: 0
pageInfo.lastCharacterIndex: 0 => should be 21
the character index is not correct for
tag, because
is replaced by “\n”, for instance
text: "
This is a test string"
textInfo,characterCount: 22 => correct
pageInfo.firstCharacterIndex: 0
pageInfo.lastCharacterIndex: 21 => correct
textInfo.characterInfo[0].character = “\n” => correct
textInfo.characterInfo[0].character.index = 0 => should be 3
text: “<color=#ff00ff>This is a test string”
textInfo,characterCount: 21 => correct
pageInfo.firstCharacterIndex: 0
pageInfo.lastCharacterIndex: 20 => correct
textInfo.characterInfo[0].character = “T” => correct
textInfo.characterInfo[0].character.index = 15 => correct
Library\PackageCache\com.unity.textmeshpro@1.5.0-preview.14\Scripts\Editor\TMPro_FontAssetCreatorWindow.cs(11,19): error CS0234: The type or namespace name ‘TextCore’ does not exist in the namespace ‘UnityEditor’ (are you missing an assembly reference?)
I know I’m late to the party, but I ran into this too. Can anyone confirm this as a fix?
in TMPro_Private.cs
I changed this on line 3263
else if (m_characterCount == totalCharacterCount - 1)
m_textInfo.pageInfo[m_pageNumber].lastCharacterIndex = m_characterCount;
to this
else if (m_characterCount == totalCharacterCount)
m_textInfo.pageInfo[m_pageNumber].lastCharacterIndex = m_characterCount;
The code seems to revert after restart, but I’m not sure it recompiles when it reverts, because I haven’t had any issues since I’ve changed it. The lastCharacterIndex is set to 0 by default, and the if/else block they have setup would allow something fall through and just stay at that default.
Just came across this - PageInfo.lastCharacterIndex will return 0 if the text’s string ends with a newline character. This is a very easy issue to lose a lot of time to, would greatly appreciate it getting fixed!