GUILayout.BeginScrollView won't scroll

Hi All,
in the editor I can open a window that shows all my sprites. However there’s a lot of them so I’d like to be able to scroll down the list. I can get the window to open. I can see the scroll bar but my image don’t scroll. Can anyone advise please. My code is below, first opening the window, then the on gui with the scroll.

    [MenuItem( "Slot Tools/Spritess", false, 0 ) ]
    internal static void initSpritess( )
    {
        var window = ( SpritesDesigner_Window ) GetWindow ( typeof( SpritesDesigner_Window ), false, "Sprites View");
        window.maxSize = new Vector2( window_x_size, window_y_size );
        window.minSize = reelwindow.maxSize;
        window.Show( );

    }

the scroll part

    void OnGUI () 
    {


        texture = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/Games/demo1/Texture/test.png", typeof(Texture2D));


        int x = 10, y = 10;



        Sprites_Class Spritesobject = new Sprites_Class ();
        Spritesobject = tcp.SpritesObject;


        scrollPosition = GUILayout.BeginScrollView( scrollPosition, false, true,  GUILayout.Width(380),  GUILayout.Height(700));

        Debug.Log (Spritesobject.NumberOfSprites);


        for (int i = 0; i < Spritesobject.NumberOfSprites; i++) 
        {


       
            if (texture) 
            {
                EditorGUI.DrawPreviewTexture ( new Rect ( x , y, 100, 100), texture);
            }


            Sprites_Data data = Spritesobject.SpritesList[ i ];

            /*name*/
            GUILayout.BeginArea( new Rect( x+125 , y ,100, 20) );
            GUILayout.Label( "Name", EditorStyles.boldLabel );
            GUILayout.EndArea( );
            GUILayout.BeginArea( new Rect( x+200 , y ,100, 20) );
            GUILayout.Label( data.name_string );
            GUILayout.EndArea( );



            y += 150;

        }


        GUILayout.EndScrollView();

OK fixed it by adding an empty label bigger than the window below the begin scroll

eg

        scrollPosition = GUILayout.BeginScrollView( scrollPosition, false, true,  GUILayout.Width(380),  GUILayout.Height(700));

        GUILayout.Label ("", GUILayout.Width ( 380 ), GUILayout.Height ( 1500 ) );  << much bigger

I’m sure this cant be the official way but there seems to be vert little documentation or tutorials, unless Im searching under the wrong terms.

2 Likes

It’s hacky, but it works for me. Nice find.

you’re the besttt… thank youuu… <3