Yes, this thread again. My latest n00b adventures involve deciphering the GUI system. I’m doing a little test-harness for a dialogue experiment. This seems like a simple problem but I’ve been butting my head against it all morning. Every thread / video / blog post I can find on the topic seems to assume a statically-sized text object.
The program periodically adds new lines of text to a Text object, and when the Text object vertically expands beyond the size of the masked area, I want the Scrollbar to automatically update to reflect how much content is off-screen (masked). Nothing oddball there, scrollbars have worked this way for decades – except in Unity, apparently. Additionally I’m setting the Scrollbar value to the bottom with the intent of showing the newly-added content.
The part which works is that the textbox grows and the masking clips it at the bottom.
One problem is that the scrollbar seems to ignore the size of the text content. As the content exceeds the mask area, the scroll Handle stays full-sized; it does not indicate there is content off the bottom of the screen, nor does it respond to setting the value to scroll all the way down.
Another stranger problem is that if I manually grab and drag the Text content (once it has grown beyond the mask bounds), the scroll Handle (which occupies 100% of the Sliding Area) starts to shrink proportionally with how far I drag the Text. Then for some reason it bounces back to the top.
The hierarchy is like this, which I believe to be correct:
The various important-seeming non-default Inspector settings are:
Canvas, Panel - at defaults
ScrollRect Mask - Content is the Text object; Vertical Scrollbar is the Scrollbar object; Horizontal is unchecked
Text - pivot anchored to the top of the parent (I believe this makes it expand downward as it resizes, maybe this is the problem?); stretch is horizontal only; Horizontal is Wrap; Vertical is Overflow; Align is left / top
Scrollbar - Direction is Bottom To Top
The test-code is dead simple:
public void ButtonClick_Reset()
{
dialogue.text = "";
lineCountdown = 100;
nextTick = 0f;
}
void Update()
{
if(lineCountdown > 0 && Time.time > nextTick)
{
dialogue.text += "this is line " + lineCountdown.ToString() + "\n";
dialogueScrollbar.value = 0f;
lineCountdown--;
nextTick = Time.time + 0.1f;
}
}
So what am I missing?