Scrolling Textbox?

Cross-posting from UnityGUI for visibility.

I’m trying to build a GUI scrolling textbox where the content will be of unknown length and will change (but not user editable).

While BeginScrollView is nice, I am forced to determine the scroll height before I build any content, not that there’s any way to poll the height of content or to get a TextArea to auto-adjust its height depending on its content.

Bump. Anyone?

Don’t post the same thing in 2 different forums. Also - try and be a bit more polite when you ask for help (referring to your response in the other forum). You’re not effectively describing what the issue you’re trying to solve is. Why can’t you use a ScrollView? Why can’t you use a GUILayout.Label to print the text to the screen since it will resize for you?

I posted it in the GUI forum first, but there seems to be low-traffic over there so I also posted it here, because it is also a scripting issue.

Why can’t you use a ScrollView?

Because I don’t know how tall the text needs to be. To quote myself, “I am forced to determine the scroll height before I build any content.”

Why can’t you use a GUILayout.Label

Because I can’t position it where I want to? GUILayout decides the positioning for me, and sorry, but I’m working to another designer’s design. I can’t just go all willy nilly and let Unity decide where things go.

Also, the text still doesn’t scroll.

You’re not effectively describing what the issue you’re trying to solve is

Does this help?

I suppose I should note, that scrolling area is positioned at 15,427 relative to the upper left corner of the GUI.Window

Simply put:

I need a scrolling text box for text of indeterminate (at compile-time) length.

private Vector2 scrollPos;
public string textToDisplay;

void OnGUI()
{
     scrollPos = GUI.BeginScrollView(new Rect(...position...), scrollPos, new Rect(...view area...));
     GUILayout.Label(textToDisplay);
     GUI.EndScrollView();
}

Any reason something like that wouldn’t work? Or is that what you’re already doing?

Gives me this:

The size of the scroll area is required to be defined before the content of indeterminate height, hence the issue.

Ok - now I see. The only way I know of to do what you’re talking about is to use GUILayout.BeginScrollView(). If you need absolute positioning then I would wrap the ScrollView in a GUI.BeginGroup()/EndGroup() which is positioned where you need it to be.

Ah ha. There we go.

Took some finagling (the Group had to be positioned about 15 pixels left and 40 pixels up and needed to be 10 pixels wider and 40 pixels taller) but it worked.

Thanks.

Draco18s can you post the code to your final result?

On Monday I can.

It’s close to:

GUI.Group(rect_where) {
GUILayout.ScrollView(rect_where) {
GUILayout.Label(the_very_long_string);
}
}

The two rects aren’t the same, there needs to be a slight fudge area, as the scrollview needs to be inset from all sides a small amount.

Here’s the code I used.

GUI.BeginGroup(Rect(0,395,250,305));  //note the 250 width and 305 height compared to the scrollview size
	scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.Width(240), GUILayout.Height(275));
		GUILayout.Label(descriptString);
	GUILayout.EndScrollView();
GUI.EndGroup();

Hello all i am working on a unity project and trying to add a scrollbar within a C# Script
The code currently generates a popup window that the user can close once done reading the text that is added in the unity editor. I am trying to get a solution to this issue soon any help with this is greatly appreciated thanks.

Try the post directly above your own. That goes inside the OnGui() method of a MonoBehaviour script, attached to any game object.

I’ve only barely touched the surface of Unity 5’s new gui stuff, amounting to the placement of small text labels. So I can’t offer any help on that front.