Hello everyone, I seem to have encountered a problem with TextMeshPro, in which it ‘lies’ to me regarding the expected values and the values it gives.
(Using Unity 2019.2.10f1 , TMP 2.0.1 from package manager, claiming to be up to date)
Specifically, it seems that if you call TMP_Text.GetPreferredValues(someTextThatWouldBeWrapped, someLimitedValue, someNotLimitedValue), and you have wrapping enabled…
- the height returned would be that of the multiple lines of the text that got wrapped, which is fine
- the width returned would be that of the text as one line, which is not expected because the height is now that of multiple lines.
Even worse, after the text has been wrapped, trying to check the text.bounds.size or text.textBounds.size gives the values without wrapping at all, even after using Canvas.ForceUpdateCanvases() to force the canvas to update.
Is there any way to get the properly wrapped text’s actual sizes? I am trying to force text to wrap only if it would exceed a certain arbitary value and regardless of the case, ensure the text is in a box of its proper minimal size along with other elements. not being able to get the proper wrapped bounds makes this impossible.
For extra reference, here is a gif displaying the issue Imgur: The magic of the Internet
The gif shows the code in action, but in the case of CriticalStrikeChance, the text gets wrapped, and the preferred size it reports with limited width is (308, 34) , and the size with unlimited width is (308, 16) - the preferred height increases without actually lowering the preferred width.
Thanks for reading, any help to getting the proper wrapped values would be appreciated!