So i know you can set a Text Mesh Pro to auto-size the font to fit it’s parent container BUT what i want is the opposite, to keep a font size and expand the parent/s to fit the text, this is my text panel, i use it mainly for tooltips/show info (first image).
The second image is how i’d like it to work (fit container to text mesh pro size/lines).
And the third image shows how it works and how it should work.
I’ve tried messing around with vertical/horizontal layouts, content fiters, layout elements… with no luck.
Hope to find some help here, thanks!
Hi again, i’m still trying to do this 
Help is <3
I just found a way to change the rectTransform to the overflowing text size.
public RectTransform LineOneText;
if(LineOneText.GetComponent<TMPro.TMP_Text>().isTextOverflowing){//change rectTransform only if text overflows
Vector2 temp = LineOneText.sizeDelta;
temp.y = LineOneText.GetComponent<TMPro.TMP_Text>().preferredHeight;
LineOneText.sizeDelta = temp;
}
though you could also just do it like this instead:
//change rectTransform to preferredHeight
Vector2 temp = LineOneText.sizeDelta;
temp.y = LineOneText.GetComponet<TMPro.TMP_Text>().preferredHeight;
LineOneText.sizeDelta = temp;
You don’t need any code to do this. Put Tmp Text as a child of the game object with a Layout Group and Content Fitter components. Choose Preferred Size for horizontal/vertical. In combination with Layout Element and Preferred Width/Height you’ll have full control of the parent’s size
3 Likes