- Home /
GUILayout beginArea not working with scrollview
I just converted a GUILayout area to be scrollable, and suddenly it doesnt respect the area it is placed in. In the code below, if I comment out the beginScrollview line and the endscrollview line, the list of buttons displays in a bar down the right side of the screen. if I run it as is, they display in a bar down the left side of the screen, and I am unable to change the size or position of the bar by adjusting the XYWH variables (well I can change the buildingMenuH variable and it makes the area shorter as expected, but the others do nothing). This example is almost identical to the one in the docs so I dont know what is going on.
buildingMenuX = Screen.width*0.9;
buildingMenuY = Screen.height*0.1;
buildingMenuW = Screen.width*0.1;
buildingMenuH = Screen.height*0.8;
GUILayout.BeginArea(Rect(buildingMenuX,buildingMenuY,buildingMenuW,buildingMenuH));
buildMenuScrollPosition = GUILayout.BeginScrollView(buildMenuScrollPosition);
GUILayout.BeginVertical();
for(i=0;i<buildings.length;i++)
{
//some buttons
}
GUILayout.EndVertical();
GUI.EndScrollView();
GUILayout.EndArea();
Answer by Berenger · Jun 11, 2012 at 03:21 PM
I usually format GUI stuff that way. Doesn't change compilation / execution, but it sure help me oversee what's going on :
buildingMenuX = Screen.width*0.9;
buildingMenuY = Screen.height*0.1;
buildingMenuW = Screen.width*0.1;
buildingMenuH = Screen.height*0.8;
GUILayout.BeginArea(Rect(buildingMenuX,buildingMenuY,buildingMenuW,buildingMenuH));
buildMenuScrollPosition = GUILayout.BeginScrollView(buildMenuScrollPosition);
GUILayout.BeginVertical();
for(i=0;i<buildings.length;i++)
{
//some buttons
}
GUILayout.EndVertical();
GUI.EndScrollView(); // !!!
GUILayout.EndArea();
Then, you can easily see what is your problem. You're calling GUILayout.BeginScrollView and GUI.EndScrollView.
The formatting didn't help me, it still took me ages to spot what you meant. Thank you for the answer though.
I agree with Dunkhan's comment. Also took me forever to see what was wrong. For anyone who comes to this page in the future and is still confused... the calls are mismatched. GUILAYOUT.BeginScrollView vs GUI.EndScrollView (CAPS for emphasis.) GUILayout is not the same as GUI.
Your answer
Follow this Question
Related Questions
Unity GUI fitting item list with max size 0 Answers
Why is my vertical layout group not spaced correctly? 1 Answer
Add a gui layout into a scroll view 1 Answer
I need help in making a GUI layout scroll view 3 Answers
Show content with scrollbar? 2 Answers