how to make a stupid scrollview?

I’ve been at this for two hours now… Something that is supposed to be easy to implement has gotten the best of me…

I’m trying to implement a scrollview into my window…

Here’s what I have in my window:

Vector2 scrollPosition = Vector2.zero;  //Global vector2...

void DoMyWindow(int windowID) {
        scrollPosition = GUI.BeginScrollView(new Rect(10,50,480,100), 
                                             scrollPosition, 
                                             new Rect(0,0,400,400));
        //GUI.skin.box.wordWrap = true;
        GUI.TextArea(new Rect(0,0,400,400),displayText);
        GUI.EndScrollView();

        GUI.Label(new Rect(10, 20, 100, 100), "Version: " + Version.x.ToString("F0") + "." + Version.y.ToString("F0") + "." + Version.z.ToString("F0") + "." + Version.z.ToString("F0"));
        if (GUI.Button(new Rect(10, 300, 480, 35), "Send Mail"))
        {
            SendMail();
        }
       // GUILayout.BeginArea(new Rect(10, 45, 480, 100));

       // GUILayout.EndArea();
        userComments = GUI.TextArea(new Rect(10,150,480,150), userComments, 1000);
        Debug.Log(scrollPosition.ToString());
        GUI.DragWindow(new Rect(0, 0, 10000, 10000));
    }

I can literally SEE my scrollPosition change in the Debug.Log… But the GUI isn’t changing for some reason…

WHAT IS THE PROBLEM???

For some reason it just will not work… I have to click the very bottom of the scrollbar and drag UP for it to scroll down… Why is this happening?

I mean, I saw some posts from 2009 that said Unity knew about this bug… I figured it would be fixed in 2014!

Bump… Seriously, I was thinking about buying pro until I found this… I’m not going to buy a $2,000 piece of software unless it has a functional GUI system…

I believe that GUI stuff has to be in the OnGUI method of a class. I’m guessing yours isn’t, since the code works for me in an OnGUI method. Instead of calling in the scrollview with the DoMyWindow method, set up something like this:

public class MyGuiStuff {
    bool showScrollView = true;
    Vector2 scrollPosition = Vector2.zero;  //Global vector2...
    private void OnGUI()
    {
        if (showScrollView)
        {
            scrollPosition = GUI.BeginScrollView(new Rect(10, 50, 480, 100),
                                                 scrollPosition,
                                                 new Rect(0, 0, 400, 400));
            //GUI.skin.box.wordWrap = true;
            GUI.TextArea(new Rect(0, 0, 400, 400), displayText);
            GUI.EndScrollView();

            GUI.Label(new Rect(10, 20, 100, 100), "Version: " + Version.x.ToString("F0") + "." + Version.y.ToString("F0") + "." + Version.z.ToString("F0") + "." + Version.z.ToString("F0"));
            if (GUI.Button(new Rect(10, 300, 480, 35), "Send Mail"))
            {
                SendMail();
            }
            // GUILayout.BeginArea(new Rect(10, 45, 480, 100));

            // GUILayout.EndArea();
            userComments = GUI.TextArea(new Rect(10, 150, 480, 150), userComments, 1000);
            Debug.Log(scrollPosition.ToString());
            GUI.DragWindow(new Rect(0, 0, 10000, 10000));
        }
    }
}

Right… I was definitely able to make it in OnGUI… But why wouldn’t it work in a window? I mean, that kind of defeats the purpose of a window if you are unable to use controls inside of it… I figure if I make a thread with enough hype about it, UT will fix this 5-year-long bug…

I’m not sure what you mean about it not working in a window. If you mean why it won’t work in a custom method, it’s because Unity needs to know where your GUI code is going to be; it can’t just tell where to look for updates to GUI elements and button clicks, it needs to be in a method that Unity knows will contain the GUI related code.

It does work in a window. You must be doing something wrong.
Heres a minimal sample that works.

	Rect windowRect = new Rect( 100, 100, 200, 300 );
	Rect innerRect = new Rect( 0, 0, 400, 400 );
	Rect outerRect = new Rect( 20, 50, 80, 80 );
	Vector2 scroll;

	void OnGUI () {
		windowRect = GUI.Window( 0, windowRect, WindowFunction, "Window!" );
	}

	void WindowFunction ( int windowID ) {
		GUILayout.Label( "Window label" );
		scroll = GUI.BeginScrollView( outerRect, scroll, innerRect );
		GUI.Label( new Rect( 0, 0, 200, 20 ), "Scroll label" );
		GUI.Box( new Rect( 40, 40, 200, 200 ), "Scroll Box" );
		GUI.EndScrollView();
		GUI.DragWindow();
	}

It is still not working for me lol. Even with your example… Good to know it isn’t a unity bug though.

Nothing is resetting scrollPosition elsewhere, is it? Or is an exception being thrown before it gets to GUI.EndScrollView()? What happens if you try using the default GUI skin?

Does the Unity GUI quest log window work for you in the Dialogue System? It uses a scroll view inside a window. If it works, you could always grab the source out of Scripts/Source Code.unitypackage and pick it apart for any differences.

Ahh I did not know it used that. No, there is definitely no exceptions being thrown, and there is nothing resetting it anywhere. I actually had a debug in OnGUI to let me know the value of scrollPosition, and it was definitely giving me the correct numbers. For some reason, though, it fixed itself… Don’t ask how lol, I don’t know. We were in the process of making our Bug Report window into an NGUI window since scrollview didn’t work, but we tested it again, and it worked… It was weird lol

EDIT:

Figured out what the problem was. There were two of these scripts in the scene.