UPDATE: the bug in TMP is the calculation and use of “m_lineOffset” - this is artificially and incorrectly set to a large value on the first time a TMP text is calculated, with the source code comment “Compute potential new line offset in the event a line break is needed.” – but it is then applied even for lines with no line-break. After the first time it’s been applied, it is reset to zero and never again artificially inflated.
CURRENT WORKAROUND: massive performance penalty to all UI, any time you use TMP for anything you have to hammer the TMP API calls and re-do every size of every TMP multiple times until they settle down and stop changing. This seems to affect about 1 in every 5 real-world UIs - I don’t know what the cause of TMP’s incorrect internal calculations is, but it doesn’t affect all UIs. Sometimes even a very short piece of text - just 5 characters - is enough to trigger it, other times you can have a UI with dozens of different texts and not see the bug at all.
I’ve narrowed down a bug that’s affecting all layout in editor to: TMP returns inconsistent results from its “preferredWidth”/“preferredHeight”
Traditionally TMP returned more accurate results for these than it does for .textBounds – but in recent TMP builds (e.g. the one bundled with Unity 2022) I’m seeing that the ‘preferred*’ API calls are terrible. Call the same method twice in the same frame and you get different results, when nothing has changed between one call and the next. This makes the API literally useless.
Is textBounds now officially the ‘supported’ way to measure text size in TMP?
OR … is there a 3rd API call we should be using somewhere instead?