How to set RectTransform size relative to the size of the textbox?

Hello everyone,

I’m doing a messages sorting system at the moment, for the Console I’m making for my game and currently I ran into one problem. I’m trying to set the message rectTransform size (height) to the size of the text box (TextMeshProUGUI). Similar way ContentSizeFitter works.

Is there a way to get a size of the TextMeshProUGUI textbox?

I tried using (TextBounds and Bounds) size values, but it didn’t really helped cause the size value of y for example is enormously huge.

Maybe I’m just missing something. Can someone give some advice on this? Thanks.

I ended up using GetPreferredValues() that was suggested by the user: Antistone.

Post Link (Forum): https://forum.unity.com/threads/how-to-set-recttransform-size-relative-to-the-size-of-the-textbox.566923/