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*);*
 *if (GUI.Button(new Rect(15, loadButtonPos, 200, 10), curFile)) {*
 *showLoadPopup = false;*
 *saveFileName = curFile;*
 *GUI.EndScrollView ();*
*<p>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.</p>*
*<p>When I do that, my scrollview jitters at a very high speed between the top and bottom of the scrollview. </p>*
*<p>I can't see what's wrong with it, so I hoped somebody else with a non-steamed brain could help.</p>*
*<p>Thanks - Elliot Bonneville</p>*

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:


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 Redirect to... title of new-page

August 2017