4.6 UI Text rect does not expand automatically

Hello,

I have a window that has a lot of text inside but the text is filled in dynamically. The problem is that the rect of text object does not grow to accommodate the text which makes text scrolling not work.

Am I doing something wrong or is it a bug? Or is that intentional?

I’m using unity 4.6.0b18

Thanks a lot

You will want to use the “content size fitter” component as mentioned by @Morning. Example image included.

[33364-screen+shot+2014-10-06+at+2.14.37+pm.png|33364]

In case you’re still needing this, I Just got this working with this little script that you can attach to the Text object. The Text component luckily has a property called “PreferredHeight” which is just the height of the overflowing text. So set the height of the textbox to the preferred height and boom you’re golden.

    RectTransform rt;
	Text txt;

	void Start () {
		rt = gameObject.GetComponent<RectTransform>(); // Acessing the RectTransform 
		txt = gameObject.GetComponent<Text>(); // Accessing the text component
	}

	void Update () {
		rt.sizeDelta = new Vector2(rt.rect.width, txt.preferredHeight); // Setting the height to equal the height of text
	}

And that’s all it takes.