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?
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
}