Inadequate text width textmeshpro

I’m trying to get the width of the text. GetRenderedValues returns -4.294967E+09. The text is displayed normally.

T1 = GameObject.Find("X").GetComponent<TextMeshPro>();
TempPartX = T1.text;

T2 = GameObject.Find("BeforeX").GetComponent<TextMeshPro>();
TempPartBefore = T2.text;

T3= GameObject.Find("AfterX").GetComponent<TextMeshPro>();
TempPartAfter = T3.text;

T4= GameObject.Find("Solution").GetComponent<TextMeshPro>();
TempPartSolution = T4.text;

T2.text = TempPartT2 + TempPartT4 + TempPartT3;
T3.text = TempPartT2 + TempPartT4 + TempPartT3;
T4.text = TempPartT2 + TempPartT4 + TempPartT3;
T1.text = TempPartT2 + TempPartT1 + TempPartT3;

widthX = T1.GetRenderedValues().x; //-4.294967E+09
widthX = T1.GetRenderedValues().y; //-4.294967E+09
widtOther = T3.GetRenderedValues().x; //-4.294967E+09

Tell me, please, am I doing everything right?

Try this

TMP_Text.preferredWidth
1 Like

Thanks, it worked!

1 Like