- Home /
Why is my scrollview jittering?
Can anyone detect any obvious problems with the following script?
int loadButtonPos = 30; string[] loadFilePaths = Directory.GetFiles(Application.dataPath + "/models/");
scrollPosition = GUI.BeginScrollView (new Rect (15,0,loadPopup.width - 30,loadPopup.height - 30), scrollPosition, new Rect (0, 0, 220, 200), false, true);
for (int i = 0; i < loadFilePaths.Length; i++) {
string curFile = Path.GetFileNameWithoutExtension(loadFilePaths[i]);
if (GUI.Button(new Rect(15, loadButtonPos, 200, 10), curFile)) {
showLoadPopup = false;
LoadData(curFile);
saveFileName = curFile;
}
loadButtonPos+=35;
}
GUI.EndScrollView ();
When I run it, my vertical scroll bar doesn't show up (even when I have far more elements invisible than onscreen) unless I set alwaysShowVerticalScrollbar to true.
When I do that, my scrollview jitters at a very high speed between the top and bottom of the scrollview.
I can't see what's wrong with it, so I hoped somebody else with a non-steamed brain could help.
Thanks - Elliot Bonneville
I've found the answer. It seems that my client rect wasn't large enough. :/ I still don't know why that would cause the strange jittering though.
Answer by IgorAherne · Aug 25, 2017 at 02:53 PM
This is an issue form 2011, but I just experienced horrible jitters of my custom script-driven layout elements. I am also getting NaN values in rect transforms & children's rect transforms.
I am strongly convinced it has to do with the internal order in which unity updates the transforms.
For future visitors, this doc explains how to "follow the rules" so that unity is not confused by you updating properties of RectTransforms, while unity tries to drive them according to its Auto-layout:
https://docs.unity3d.com/ScriptReference/UI.ILayoutElement.html
Also check out https://docs.unity3d.com/ScriptReference/UI.ILayoutController.html and in particular the ILayoutSelfController.
Layout calculation rules and order is also discussed here, in the section Technical Details https://docs.unity3d.com/Manual/UIAutoLayout.html
August 2017
Your answer
![](https://koobas.hobune.stream/wayback/20220613103812im_/https://answers.unity.com/themes/thub/images/avi.jpg)