Search Unity

EndLayoutGroup: BeginLayoutGroup must be called first

Discussion in 'Immediate Mode GUI (IMGUI)' started by DougRichardson, Mar 23, 2018.

  1. DougRichardson

    DougRichardson

    Joined:
    Oct 7, 2017
    Posts:
    74
    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);
    }
    }
     
    Wonny95, PhannGor and AlwaysBaroque like this.
  2. PsyKaw

    PsyKaw

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

    DougRichardson

    Joined:
    Oct 7, 2017
    Posts:
    74
    Was not aware of GUIUtility.ExitGUI(). Exactly what I needed. Thanks.
     
    fdasfsa, AcJoker and niki4etoo like this.
  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. DougRichardson

    DougRichardson

    Joined:
    Oct 7, 2017
    Posts:
    74
    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
    TThunder likes this.
  7. DougRichardson

    DougRichardson

    Joined:
    Oct 7, 2017
    Posts:
    74
    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. DougRichardson

    DougRichardson

    Joined:
    Oct 7, 2017
    Posts:
    74
    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. DougRichardson

    DougRichardson

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

    jaydeep01

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

    FungusMonkey

    Joined:
    Jun 30, 2016
    Posts:
    41

    Nice. Thanks.
     
  14. GachaJhovenYT

    GachaJhovenYT

    Joined:
    Feb 8, 2020
    Posts:
    2
    hello guys im having a problem with this
     

    Attached Files:

  15. koushiknaik

    koushiknaik

    Joined:
    Apr 10, 2020
    Posts:
    5
    EndLayoutGroup: BeginLayoutGroup must be called first. UnityEngine.GUIUtility:processEvent(Int32, IntPtr, Boolean&)
    I don't know what to do
     
    wlwl2 likes this.
  16. Remiah17

    Remiah17

    Joined:
    Sep 10, 2019
    Posts:
    1
    i'm getting the same error
    EndLayoutGroup: BeginLayoutGroup must be called first.
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)
    everytime i make a new script
     
    krakeninferno, wlwl2 and nco2k like this.
  17. Mrfrostzy

    Mrfrostzy

    Joined:
    Mar 16, 2020
    Posts:
    1
  18. bhoumita

    bhoumita

    Joined:
    Mar 5, 2020
    Posts:
    1
    EndLayoutGroup: BeginLayoutGroup must be called first.
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)
     
  19. Tarrag

    Tarrag

    Joined:
    Nov 7, 2016
    Posts:
    215
    when disconnecting network connection while in UI a circle showing "loading" is spinning

    EndLayoutGroup: BeginLayoutGroup must be called first.
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr, Boolean&)

    Unity 20201.0b8
     
  20. Thebuilderpro

    Thebuilderpro

    Joined:
    May 13, 2020
    Posts:
    1
    I have this error that keeps coming to me when i try to extract texture from mixamo models in unity this one
    EndLayoutGroup: BeginLayoutGroup must be called first.
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)

    Please help i've been working so hard on the game it's only the textures left for the player it's the alien soldier model
     
  21. Alcides2040

    Alcides2040

    Joined:
    Jun 19, 2020
    Posts:
    1
    usando UnityEngine;
    usando System.Collections.Generic;


    public class logicapersonaje: MonoBehaviour {
    flotante público velocidadMovimiento = 5.0f;
    flotante público velocidadRotacion = 200.0f;
    animador privado animador;
    flotador público x, y;

    // Se llama al inicio antes de la primera actualización del marco
    Inicio nulo () {
    anim = GetComponent <Animator> ();
    }

    // Actualización se llama una vez por cuadro
    Actualización nula () {
    x = Input.GetAxis ("Horizontal");
    y = Input.GetAxis ("Vertical");

    transform.Rotate (0, x * Time.deltaTime * velocidadRotacion, 0);
    transform.Translate (0, 0, y * Time.deltaTime * velocidadMovimiento);
    }

    }

    POR FAVOR AYUDA: ESE ES EL CODIGO ERROR DE VENTA SCRIP Y ME
    EndLayoutGroup: BeginLayoutGroup debe llamarse primero.UnityEngine.GUIUtility: ProcessEvent (Int32, IntPtr)

    Alguien podria ayudarme Por favor
     
  22. altepTest

    altepTest

    Joined:
    Jul 5, 2012
    Posts:
    1,115
    still present in unity 2019.4.1f1 when importing fbx files
     
    krakeninferno and brahim003 like this.
  23. whatyyyyyy

    whatyyyyyy

    Joined:
    May 12, 2020
    Posts:
    1
    You should delete all the library not working.I just fix it recently.
    upload_2020-7-2_16-25-48.png
     
  24. Brayubro

    Brayubro

    Joined:
    Aug 8, 2020
    Posts:
    1
    I Don't Know What To Do
    It says end layer group begin layer group must be called first
    Code:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class PlayerMovement : MonoBehaviour {

    public CharacterController2D controller;

    public float runSpeed = 40f;

    float horizontalMove = 0f;
    bool jump = false;
    bool crouch = false;

    // Update is called once per frame
    void Update () {

    horizontalMove = Input.GetAxisRaw("Horizontal") * runSpeed;

    if (Input.GetButtonDown("Jump"))
    {
    jump = true;
    }

    if (Input.GetButtonDown("Crouch"))
    {
    crouch = true;
    } else if (Input.GetButtonUp("Crouch"))
    {
    crouch = false;
    }

    }

    void FixedUpdate ()
    {
    // Move our character
    controller.Move(horizontalMove * Time.fixedDeltaTime, crouch, jump);
    jump = false;
    }
    }
     
  25. eldar_unity

    eldar_unity

    Joined:
    Aug 11, 2020
    Posts:
    3
    I'm getting the same error when I try to import a large raw terrain map using the (Import Raw) button in the terrain settings window.

    I'm starting with a fresh new project, so I do the following

    Create new terrain (from dropdown menu)
    go to terrain settings
    Import Raw...
    select file.

    The message appears as soon as I select the file (at the Import Heightmap window appears). I can still edit the settings in the Import Heightmap window, so I set Terrain size at 4096, 1000, 4096, but then nothing happens.

    The heightmap I'm trying to import is rather hefty (900 mb). Am I missing something?
     
    karoliskum and robske like this.
  26. Jorpro12Ob1

    Jorpro12Ob1

    Joined:
    Aug 13, 2020
    Posts:
    2
    I have the same, this is the code

    using System.Collections;
    using System.Collections.Generic;
    using System.Threading;
    using UnityEngine;

    public class PlayerControl2 : MonoBehaviour
    {
    // Start is called before the first frame update
    void Start()
    {

    }

    // Update is called once per frame
    void Update()
    {
    if(Input.GetKey("left"))
    {
    gameObject.GetComponent<Rigidbody>().AddForce(new Vector2(-1000f * Time.deltaTime, 0));
    }
    }
    }
     
  27. Jorpro12Ob1

    Jorpro12Ob1

    Joined:
    Aug 13, 2020
    Posts:
    2
    Can anyone help me?
     
  28. idk_idk

    idk_idk

    Joined:
    Aug 9, 2020
    Posts:
    1
    same issue here my code is:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;

    public class PlayerMovement : MonoBehaviour
    {
    public CharacterController controller;

    public float speed = 12f;
    public float gravity = -9.81f;

    Vector3 velocity;

    void Update()
    {
    float x = Input.GetAxis("Horizontal");
    float z = Input.GetAxis("Vertical");

    Vector3 move = transform.right * x + transform.forward * z;

    controller.Move(move * speed * Time.deltaTime);

    velocity y +gravity * Time.deltaTime;

    controller.Move(velocity * Time.deltaTime);
    }
    }
     
  29. brahim003

    brahim003

    Joined:
    Aug 3, 2020
    Posts:
    2
    end layout group: begin layout group must be called first
     
  30. brahim003

    brahim003

    Joined:
    Aug 3, 2020
    Posts:
    2
    after importing fbx file from blender
     
  31. xylerlaws

    xylerlaws

    Joined:
    Sep 22, 2020
    Posts:
    1
    i was trying to make a movement script it was popping up a different error code that i didn't know how to fix so i red a different thing but when i tried swapping stores it shode this up EndLayoutGroup: BeginLayoutGroup must be called first.anyone know how to fix this.
     
  32. gtonuimatwek

    gtonuimatwek

    Joined:
    Sep 19, 2020
    Posts:
    4
    HUDController.cs(5,45): error Cs1513: } expected
    this error is eating me up

    here is my code can anyone help

    her is my code




    using UnityEngine;
    using System.Collections;
    using UnityEngine.UI;

    public class HUDController : MonoBehaviour {

    using UnityEngine.UI;
    public UI.Text Score;
    public UI.Text BallsLeftText;
    public UI.Text ScoreText;
    public UI.Image Logomarca;
    public UI.Text BallsLeft;

    // Use this for initialization
    void Start () {
    int scWidth = Screen.width;

    if (scWidth > 1200) {
    Score.transform.position = new Vector3 (Score.transform.position.x-0.05f, Score.transform.position.y, Score.transform.position.z);
    Score.fontSize = 80;
    ScoreText.transform.position = new Vector3 (ScoreText.transform.position.x-0.02f, ScoreText.transform.position.y, ScoreText.transform.position.z);
    ScoreText.fontSize = 140;
    BallsLeft.transform.position = new Vector3 (BallsLeft.transform.position.x-0.05f, BallsLeft.transform.position.y, BallsLeft.transform.position.z);
    BallsLeft.fontSize = 80;
    BallsLeftText.transform.position = new Vector3 (BallsLeftText.transform.position.x-0.02f, BallsLeftText.transform.position.y, BallsLeftText.transform.position.z);
    BallsLeftText.fontSize = 140;
    }

    //(Screen.height / defaultScreenSize) * defaultFontSize

    // GUI.Label (new Rect (scWidth/2.6f, scHeigth/7, scWidth/4, scHeigth/4), msgTexture);
    }

    // Update is called once per frame
    void Update () {

    }
     
    krakeninferno likes this.
  33. Blake_Fitzgerald

    Blake_Fitzgerald

    Joined:
    Jul 11, 2019
    Posts:
    2
    Hey everyone make sure you didn't click the button next to the play game button on unity 2020 that says local/global - i had this problem and same error in my game and could not play test what im making because i accidentally pressed the button at some point apparently.
     
  34. SonicTheHedgiehog

    SonicTheHedgiehog

    Joined:
    Nov 15, 2020
    Posts:
    20
    you haven't placed the } of the class. also if your update is empty just remove it.

    just place an } after update method.
     
  35. yonatanstern2004

    yonatanstern2004

    Joined:
    Feb 24, 2021
    Posts:
    2
    Hey so im really new to coding, and I've been trying to make a game for fun, but I get that error and I have no idea what you said. I've tried to look everywhere but I cant find any other people that have simplified it in an easier way. Would you please be able to do that?
     
  36. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    2,252
    Which error? Please include the top few lines of the error from the Unity Console.
     
  37. yonatanstern2004

    yonatanstern2004

    Joined:
    Feb 24, 2021
    Posts:
    2
    this is the error:
    EndLayoutGroup: BeginLayoutGroup must be called first.
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)
     
  38. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    2,252
    Does this occur in editor code you wrote? If so provide a code snippet and place it in the message using the Code icon in the message toolbar (which makes it easier for everyone to read).
    If it just occurs sometime when using the Unity editor it is more likely an asset you downloaded from the Asset Store OR a bug in the Unity editor (which there are several that generate this error).
     
  39. AnimationSB

    AnimationSB

    Joined:
    Mar 8, 2021
    Posts:
    22
    I am experiencing the same problem
    upload_2021-4-8_13-50-2.png

    when I double click here to check where its coming from, VS2019 loads, but then nothing happens. even if i double click the error again, nothing loads up on VS2019

    I saw some fixes shared here, on some code, but I can't load any code to try them out.

    upload_2021-4-8_13-50-47.png
     
  40. herofyt

    herofyt

    Joined:
    Jun 7, 2021
    Posts:
    2
    im dum
     
  41. karoliskum

    karoliskum

    Joined:
    Apr 12, 2020
    Posts:
    1




    I have same problem maybe you found an answer?
     
  42. SamurIDev

    SamurIDev

    Joined:
    Jul 28, 2021
    Posts:
    1
    I am getting this error and i don't know how to trace it, all i know is that it is rooted in TextMeshPro.
    Image of the error: upload_2021-7-28_9-26-47.png

    I am brand new to unity so i have no idea what i am doing. I have done all of the same stuff on a separate game and not had this issue before. What should I do?

    EDIT: Nevermind! I just reloaded all of the scenes and that somehow got rid of the error! Unity is weird lol
     
    Last edited: Jul 28, 2021
  43. omgur

    omgur

    Joined:
    Sep 5, 2022
    Posts:
    1
    Guys, I've found a noob solution! ;) I create a new behaviour script with default name -> copy all the code from the previous script into it -> delete the previous script. Strange, but it works! No error!
     
  44. gekaoyazilim

    gekaoyazilim

    Joined:
    Apr 10, 2023
    Posts:
    2
    UnityEditor.BuildPlayerWindow+BuildMethodException: Error building Player because scripts have compile errors in the editor
    at UnityEditor.BuildPlayerWindow+DefaultBuildMethods.BuildPlayer (UnityEditor.BuildPlayerOptions options) [0x002bf] in <7105be432fb64891b07085914e6cd5c1>:0
    at UnityEditor.BuildPlayerWindow.CallBuildMethods (System.Boolean askForBuildLocation, UnityEditor.BuildOptions defaultBuildOptions) [0x00080] in <7105be432fb64891b07085914e6cd5c1>:0
    UnityEngine.GUIUtility:processEvent (int,intptr)


    help me?
     
  45. FargleBargle

    FargleBargle

    Joined:
    Oct 15, 2011
    Posts:
    774
    Most of the posts above show this error in response to a user script. I get it whenever I import an FBX model and extract its textures and materials to a folder:

    EndLayoutGroup: BeginLayoutGroup must be called first.
    UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

    Then, when I first drag the new model into my scene, I get this:

    UnityEditor.ObjectPreview was not disposed properly. Make sure that base.Cleanup is called if overriding the Cleanup method. If you are implementing this in an Editor or EditorWindow, don't forget to call ObjectPreview.Cleanup in OnDisable.
    UnityEditor.ObjectPreview:Finalize ()

    The only scripts involved in this case are from Unity's internal codebase. Not sure what to do to prevent them, but they don't seem to indicate a real problem, since the models, textures, and materials all import fine. They just generate a lot of useless and distracting console noise in the process. :rolleyes:
     
    Last edited: Apr 22, 2023
  46. VomitCake

    VomitCake

    Joined:
    Sep 11, 2023
    Posts:
    1
    I don't exactly know what you're meaning but I tried extracting materials, and had to make a folder under assets to extract to. Though I'm using 2019.4.31f1 so it might not be what you're looking for.
     
  47. FargleBargle

    FargleBargle

    Joined:
    Oct 15, 2011
    Posts:
    774
    My procedure is:
    1. Import an FBX model
    2. Create a new folder for its materials and textures
    3. Under the Materials tab, click Extract Textures, and select the new folder as the destination
    4. Under the Materials tab, click Extract Materials,and select the same new folder as the destination
    At this point, I get the first error:
    Code (CSharp):
    1. EndLayoutGroup: BeginLayoutGroup must be called first.
    2. UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
    The second error usually waits until I place the new model into my scene hierarchy. Again, they don't seem to indicate a serious problem. Once I clear them from the console, they don't come back, and the scene plays without further problems. It's just aggravating that they show up at all, considering these are what I would consider normal editor operations, that don't involve user scripts, or any non-Unity plugins. Errors are supposed to mean something, and these apparently don't mean anything.
     
  48. Darkgaze

    Darkgaze

    Joined:
    Apr 3, 2017
    Posts:
    397
    I have this error too in 2020.3+ when I import a Png image. After that is called, it returns this.

    I've tried using GUIutility.ExitGUI() as recommended by some people (still don't understand what that does, really).
    And putting Vertical Layouts around all items, made sure every layout group has an opening and closing action.

    But still getting this error, which by the way, is internal, there is no BeginLayoutGroup anymore since a very old unity version. No idea...
     
  49. sstrong

    sstrong

    Joined:
    Oct 16, 2013
    Posts:
    2,252
    Essentially there are multiple passes for editor layout. If not all passes have the same content, you can get this error after U2019.1 (from memory). The solution is to call the ExitGUI() to ignore all other passes immediately after you've changed the layout.
     
  50. Darkgaze

    Darkgaze

    Joined:
    Apr 3, 2017
    Posts:
    397
    Thanks.
    I think I mentioned I used ExitGUI(). If I run that, it shows no GUI.