Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

GUI Error: You are pushing more GUIClips than you are popping.

Discussion in 'Immediate Mode GUI (IMGUI)' started by danielbutler94, Feb 3, 2013.

  1. danielbutler94

    danielbutler94

    Joined:
    May 28, 2012
    Posts:
    83
    Hello!

    On the following code I get the 'GUI Error: You are pushing more GUIClips than you are popping.' error.

    Code (csharp):
    1.    
    2.     void OnGUI()
    3.     {
    4.        
    5.        
    6.         if (RenderGUI == true)
    7.         {
    8.        
    9.         GUI.BeginGroup (new Rect (Screen.width / 2 - 200, Screen.height / 2 - 200, 400, 400));
    10.         GUI.Box (new Rect (0,0,400,150), "Choose your Fate...");
    11.         GUI.EndGroup();
    12.        
    13.         if (GUI.Button (new Rect (105,40,200,30), "Human Team")) {
    14.            
    15.         GameObject player = Network.Instantiate(humanPref, new Vector3(305,-80,320) , Quaternion.identity, 0) as GameObject;
    16.         RenderGUI = false;
    17.            
    18.  
    19.         }
    20.        
    21.            
    22.            
    23.         }
    24.     }
    What could be the issue?

    When I click on the error it references an Engine file under the directory C:/BuildAgent/work/812c4f5049264fad/Runtime/GUIClip.cpp at like : 383
     
    Last edited: Feb 3, 2013
  2. Jaimi

    Jaimi

    Joined:
    Jan 10, 2009
    Posts:
    6,240
    OnGui can be called multiple times per frame. Maybe something with turning the RenderGUI off inside OnGui?
     
    twobob likes this.
  3. danielbutler94

    danielbutler94

    Joined:
    May 28, 2012
    Posts:
    83
    Do you think calling the RenderGUI off with a function would fix the issue?
     
  4. Jaimi

    Jaimi

    Joined:
    Jan 10, 2009
    Posts:
    6,240
    I would try to just comment it out first, to see if that is actually the problem. If so, i would move the turn on/off outside of OnGui, into another function - LateUpdate, perhaps.
     
  5. ultraviol3nt

    ultraviol3nt

    Joined:
    Jan 17, 2010
    Posts:
    155
    On line 8, you open a GUI.BeginGroup. You have to use a GUI.EndGroup at some point, suggestively line 16. The same message will be produced if you use GUILayout.BeginArea and do not use the accompanying GUILayout.EndArea later in the code.
     
  6. barinelg

    barinelg

    Joined:
    Jun 1, 2010
    Posts:
    95
    Unity OnGUI does 2 passes: 1 to draw stuff and 1 to check for input. I think what can happen is that if RenderGUI is set to false in-between these 2 passes, you can get an error like that. Try what Jaimi said and comment that if statement out. If you suddenly notice everything is working, then have the RenderGUI be set outside of the OnGUI call.
     
  7. ultraviol3nt

    ultraviol3nt

    Joined:
    Jan 17, 2010
    Posts:
    155
    Again, it's nothing other than the fact that he never used a GUI.EndGroup. It may be 2 different passes, but they occur in the same frame. If the boolean is carried out at the start of the frame, it's not going to get caught in between passes.
     
  8. barinelg

    barinelg

    Joined:
    Jun 1, 2010
    Posts:
    95
    Line 10 shows a GUI.EndGroup() for me. I've also had such a boolean do that to me. If input is the first pass, and a GUI input sets that boolean, it would seem to me that it could interrupt things, but that latter bit is just me speculating.
     
  9. Dealzu-The-Wikid

    Dealzu-The-Wikid

    Joined:
    Feb 15, 2013
    Posts:
    3
    I have had similar problems with this, what I have done is created another script that toggles the GUI script on or off based on my conditions.
    Here is an example...

    var theGuiScriptYouWrote : theNameOfYourScript; //You will drag your script into here in the inspector
    function Update () {
    if(Input.GetKeyDown ("p")){ //Pick a button that pops it up when you press it down (if that is what you were thinking)
    if(theGuiScriptYouWrote.enabled == true){ // If you press the button the script becomes enabled, press it again it becomes disabled
    theGuiScriptYouWrote.enabled = false;
    }
    else{
    theGuiScriptYouWrote.enabled = true;

    }
    }
    }


    Also be sure to check your other scripts, there is a possibility you forgot to call endgroup on the gui script called prior to this one and therefore it wants to know why your popping a brand new one when you have not closed off the other scripts GUI.