Text.PrefferedHeight not working correctly?

Hey,

for my Quiz App I Change the Question and then wait one Frame and then check the prefferred Height then set the Size of the Text to the Height.

As far so good, this works… mostly.

I have some questions, where this does not work => I get a wrong Height, so my whole design gets pushed up and I can’t read the last line.

5660422--589201--upload_2020-4-2_11-23-14.png
This is where it doesnt work.

5660422--589207--upload_2020-4-2_11-24-33.png
Here it does work.

I tried it with:
Text.preferredHeight and Text.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, Frage_Height);
Content Size Fitter and Frage.rectTransform.rect.size.y

And yes, between setting the Text and Getting the Height I wait via yield return null
And like I said, it mostly works.

The Questions are in German, but that doesn’t matter sinze the Quiz will be German only.

No ideas?

Is this a Unity Text component or a TextMeshPro one?

Its Unity Text.

Right. I’d swap to TextMeshPro - it looks better, and preferredHeight gives the correct value right after you set the text.

If you want it to work with Unity Text, the way to fit some contained text is to have the text set to stretch with it’s container, and have the container use a content size fitter.

well, Even the Content SizeFitter does not work there…

Thats my Problem. Else i wouldnt ask for help

Ok, retested it with Content Size Fitter.

In this case the Returned Value by Text.rectTransform.rect.size.y is not the same as it shows in the Editor