Sometimes when I build up a block of UI with a textmesh pro block of text the text isn’t positioned correctly.
In the editor the “containment rectangle” is shown in the correct place but the text is misplaced to the side of it.
When this has happened then whilst in the editor modifying any field in the Text Mesh Pro UGUI component will cause the text to instantly position itself correctly.
Modifying position or any anchor in the Rect Transform component will also instantly fix the issue (scale and rotate whilst working don’t - although ctrl-z to undo the changes does).
At the moment I’ve got around it by adding a call to TextMeshProUGUI.SetAllDirty() although I suspect this isn’t particularly efficient particularly as I have a lot of text and can’t discriminate between text that works and text that doesn’t.
I also noticed that in these cases preferredHeight and preferredWidth return incorrect values whilst GetPreferredValues returns the correct ones.
I suspect I’m doing something a little “out of sequence” which is managing to confuse the dirty flags for the text but at the moment I’m struggling to figure out what.