Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  4. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

EndLayoutGroup: BeginLayoutGroup must be called first

Discussion in 'Extensions & OnGUI' started by dichardson, Mar 23, 2018.

  1. dichardson

    dichardson

    Joined:
    Oct 7, 2017
    Posts:
    47
    I have a custom editor that appends a button to the default inspector for a ScriptableObject sub-class. When this button is pressed, I run my build. Everything seems to work, but I get the following error logged to the console after the build completes:

    EndLayoutGroup: BeginLayoutGroup must be called first.
    UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)


    Sometime I get this message too:

    Expected top level layout group missing! Too many GUILayout.EndScrollView/EndVertical/EndHorizontal?
    UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)


    If I comment out the call to Builder.InteractiveBuild, the error message doesn't appear. Builder.InteractiveBuild merges multiple scenes into a single scene file and then calls BuildPipeline.BuildPlayer to build the project using that merged scene.

    There is no GUI code in Builder.InteractiveBuild, although it does call BuildPipeline.BuildPlayer which puts up a progress dialog.

    I also tried making a call to GUILayout.BeginVertical at the beginning of OnInspectorGUI to no avail.

    Any ideas as to what is going on?

    Here is the Editor's OnInspectorGUI:


    public override void OnInspectorGUI()
    {
    DrawDefaultInspector();
    EditorGUILayout.Space();

    if (GUILayout.Button("Build", GUILayout.ExpandWidth(false)))
    {
    Builder.InteractiveBuild((BuildConfiguration)target);
    }
    }
     
  2. PsyKaw

    PsyKaw

    Joined:
    Aug 16, 2012
    Posts:
    88
    Add GUIUtility.ExitGUI(); after Builder.InteractiveBuild((BuildConfiguration)target);
    It should fix your problem. Enjoy :)
     
    dichardson likes this.
  3. dichardson

    dichardson

    Joined:
    Oct 7, 2017
    Posts:
    47
    Was not aware of GUIUtility.ExitGUI(). Exactly what I needed. Thanks.
     
  4. jaydeep01

    jaydeep01

    Joined:
    May 22, 2018
    Posts:
    7
    I m getting this same error after process the code after button clicked inside OnInspectorGUI() in unity version 2018.2.5f1 mac os.

    When button click I display progress bar using EditorUtility.DisplayProgressBar() and clear it using EditorUtility.ClearProgressBar();. and also display EditorUtility.DisplayDialog() after it.
    If I comment code of progress bar and display dialog error not occurred any everything works fine.

    In my case GUIUtility.ExitGUI() not working. Any other way to solve this error?
     
  5. dichardson

    dichardson

    Joined:
    Oct 7, 2017
    Posts:
    47
    Can you post the code?
     
  6. jaydeep01

    jaydeep01

    Joined:
    May 22, 2018
    Posts:
    7
    Code (CSharp):
    1. public override void OnInspectorGUI()
    2. {
    3.     GameScript gameScript = (GameScript)target;
    4.     if (GUILayout.Button("Choose", GUILayout.Width(70), GUILayout.Height(20)))
    5.     {
    6.         string filepath = EditorUtility.OpenFilePanelWithFilters("Choose", "", filters);
    7.         EditorUtility.DisplayProgressBar("Processing..", "Shows a progress", 0.2f);
    8.         gameScript.ProcessFile(); //It takes 8-10 sec
    9.         EditorUtility.ClearProgressBar();
    10.         EditorUtility.DisplayDialog("Message", "Success.", "Ok");
    11.         GUIUtility.ExitGUI();
    12.     }
    13. }
     
    Last edited: Sep 8, 2018
  7. dichardson

    dichardson

    Joined:
    Oct 7, 2017
    Posts:
    47
    I don't know what the problem is exactly, but my guess is that you're using the API in a way the API designer didn't intend it to be used. For example, there's no point in calling DisplayProgressBar and then immediately calling ClearProgressBar in the same OnInspectorGUI invocation. In immediate mode GUI programming, you'd typically not call a bunch of functions like this in order like you have.

    If you haven't read it already, make sure to read up on Immediate Mode GUI.
     
  8. jaydeep01

    jaydeep01

    Joined:
    May 22, 2018
    Posts:
    7
    @dichardson, Actually I,m processing file by calling the method(see my updated code) in between DisplayProgressBar and ClearProgressBar and it takes 8-10 secs. Here the main problem in mac os is that after selecting the file from OpenFilePanelWithFilters the dialog windows do not disappear from the screen and ProgressBar is displayed behind the dialog windows.

    Is there any way to close the dialog window after selecting the file or another way to handle this situation?
     
    Last edited: Sep 8, 2018
  9. dichardson

    dichardson

    Joined:
    Oct 7, 2017
    Posts:
    47
    Huh. I took your code and put a sleep in to simulate the long processing and it actually worked fine for me on Windows 10 running Unity 2018.2.6f1.

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3.  
    4. [CustomEditor(typeof(NewBehaviourScript))]
    5. public class NewBehaviourScriptEditor : Editor {
    6.  
    7.     public override void OnInspectorGUI()
    8.     {
    9.         if (GUILayout.Button("Choose", GUILayout.Width(70), GUILayout.Height(20)))
    10.         {
    11.             string filepath = EditorUtility.OpenFilePanelWithFilters("Choose", "", new string[] { "CSharp", "cs" });
    12.             Debug.Log("filepath is " + filepath);
    13.             EditorUtility.DisplayProgressBar("Processing..", "Shows a progress", 0.2f);
    14.             System.Threading.Thread.Sleep(8000);
    15.             EditorUtility.ClearProgressBar();
    16.             EditorUtility.DisplayDialog("Message", "Success.", "Ok");
    17.             GUIUtility.ExitGUI();
    18.         }
    19.     }
    20. }
    21.  
    NewBehaviourScript was just a default MonoBehavior.
     
  10. jaydeep01

    jaydeep01

    Joined:
    May 22, 2018
    Posts:
    7
    In windows 10 it works fine for me but my error occurs only in mac os.:(
     
  11. dichardson

    dichardson

    Joined:
    Oct 7, 2017
    Posts:
    47
    You should report an issue. Sounds like a bug.
     
  12. jaydeep01

    jaydeep01

    Joined:
    May 22, 2018
    Posts:
    7
    Ok. thanks