Scrollbars

Hey guys, I’m back again. This time I’m trying to figure out how to make

UILayout.BeginScrollView()

work correctly. I mean, it’s working like I believe it should be, but I can’t seem to actually get the area to scroll. Do I have to set up a scrollbar for it, or is it supposed to automatically do it when content overflows? The attached picture is the layout, and here’s the code I’m using:

GUI.skin = LoadSkin;
GUILayout.BeginArea(new Rect(225, 55, 400, 500));

	GUI.Box(new Rect(5, 7, 390, 74), "", "LoadTitle");
	GUI.Box(new Rect(0, 0, 400, 500), "", "LoadBorder");

	int y = 0;
	GUILayout.BeginArea(new Rect(11, 75, 376, 425));

		saveList = GUILayout.BeginScrollView(saveList, GUILayout.Width(376), GUILayout.Height(425));

			foreach(var i in text)
			{
				GUI.Box(new Rect(0, y, 376, 20), i, "LoadLine");
				y = y + 20;
			}

		GUILayout.EndScrollView();

	GUILayout.EndArea();

	GUI.Box(new Rect(0, 0, 400, 500), "", "LoadBorder");
GUILayout.EndArea();

Your problem is that you are mixing GUI and GUILayout calls. GUILayout doesn’t have access to any Rect that GUI creates (at least to my knowledge), so as far as your scrollview is concerned, there is nothing in it. So, use GUI.BeginScrollView instead of GUILayout.BegindScrollView. You will probably have to calculate the height of the scrollable area, but that’s easy since you know the length of the list you’re iterating and the height of each element.

My suggestion is that you ditch GUILayout and set useGUILayout = false so you’ll get better performance. Unity - Scripting API: GUI.BeginScrollView , so you don’t have to look for it.

Or alternatively, change GUI.Box(new Rect(0, y, 376, 20), i, "LoadLine"); to GUILayout.Box(i, "LoadLine");