Search Unity

GUI Error: You are pushing more GUIClips than you are popping. Make sure they are balanced)

Discussion in 'UI Toolkit' started by FedeStefan, May 26, 2019.

  1. FedeStefan

    FedeStefan

    Joined:
    Aug 15, 2018
    Posts:
    221
    So i've wanted to test my game today, and when i got in and made a room, i opened my pause menu and everythings broken.


    And the error is
    GUI Error: You are pushing more GUIClips than you are popping. Make sure they are balanced).


    Heres my full gui script:

    Code (CSharp):
    1.     void OnGUI(){
    2.         GUI.skin = guiSkin;
    3.         GUI.Label(new Rect(Screen.width-190, Screen.height-80, 190, 20), " Tab - pause menu");
    4.         GUI.color = new Color(1, 1, 1, 0.7f);
    5.         if(isPaused){
    6.             GUI.color = new Color(1, 1, 1, 0.7f);
    7.             GUI.Window (0, new Rect (Screen.width/2 - 250, Screen.height/2 - 210, 500, 500), MainMenu, "Room: " + PhotonNetwork.room.name + " | Game Mode: " + gameMode);
    8.         }
    9.         //Display round countdown timer
    10.         float roundedRestSeconds = Mathf.CeilToInt(currentRoundTime);
    11.         int displaySeconds = Mathf.FloorToInt(roundedRestSeconds % 60);
    12.         int displayMinutes = Mathf.FloorToInt((roundedRestSeconds / 60)%60);
    13.         string niceTime = string.Format("{0:00}:{1:00}", displayMinutes, displaySeconds);
    14.         GUI.Box(new Rect(Screen.width/2 - 50, 45, 100, 30), niceTime);
    15.         //Display Team Scores
    16.         if(gameMode == "TDM"){
    17.             GUILayout.BeginArea(new Rect(Screen.width/3 - 100, 45, 200, 30));
    18.             GUILayout.BeginHorizontal("box", GUILayout.Width(200), GUILayout.Height(30));
    19.             GUI.color = team_1_Color;
    20.             GUILayout.Label(team_1.teamName + ":");
    21.             GUILayout.Space(5);
    22.             GUI.color = Color.white;
    23.             GUILayout.Label(team1Score.ToString());
    24.             GUILayout.EndHorizontal();
    25.             GUILayout.EndArea();
    26.             GUILayout.BeginArea(new Rect(Screen.width - Screen.width/3 - 100, 45, 200, 30));
    27.             GUILayout.BeginHorizontal("box", GUILayout.Width(200), GUILayout.Height(30));
    28.             GUI.color = team_2_Color;
    29.             GUILayout.Label(team_2.teamName + ":");
    30.             GUILayout.Space(5);
    31.             GUI.color = Color.white;
    32.             GUILayout.Label(team2Score.ToString());
    33.             GUILayout.EndHorizontal();
    34.             GUILayout.EndArea();
    35.         }else{
    36.             GUI.color = Color.white;
    37.             GUI.Box(new Rect(Screen.width/2 - 150, 80, 300, 30), "Leading Player: " + leadingPlayer);
    38.         }
    39.         GUI.color = Color.white;
    40.         if(roundEnded){
    41.             GUI.Box(new Rect(Screen.width/2 - 200, Screen.height/2 - 100, 400, 30), finalText);
    42.         }
    43.         //Fade black screen when returning to Lobby
    44.         FadeScreen();
    45.     }
    46.     void MainMenu (int windowID) {
    47.         GUI.FocusWindow(windowID);
    48.         GUILayout.Space (10);
    49.         GUILayout.BeginHorizontal();
    50.         Resolutions();
    51.         QualityWindow();
    52.         GUI.color = Color.white;
    53.         GUILayout.Space (15);
    54.         GUILayout.BeginVertical();
    55.         //Select Team to Join
    56.         if(gameMode == "TDM"){
    57.             //Team 1
    58.             if((string)PhotonNetwork.player.customProperties["TeamName"] == team_1.teamName
    59.                 || (!Player && (string)PhotonNetwork.player.customProperties["TeamName"] != "Spectators" || roundEnded)){
    60.                 GUI.enabled = false;
    61.             }else{
    62.                 GUI.enabled = true;
    63.             }
    64.             if(GUILayout.Button(team_1.teamName)){
    65.                 //Kill current player if exist
    66.                 if(!Player){
    67.                     SpawnPlayer(team_1.teamName);
    68.                 }else{
    69.                     SwapTeams(team_1.teamName);
    70.                 }
    71.                 isPaused = false;
    72.                 //Player joined team, notify everyone
    73.                 gameObject.SendMessage("PlayerJoinedTeam", team_1.teamName, SendMessageOptions.DontRequireReceiver);
    74.             }
    75.             //Team 2
    76.             if((string)PhotonNetwork.player.customProperties["TeamName"] == team_2.teamName
    77.                 || (!Player && (string)PhotonNetwork.player.customProperties["TeamName"] != "Spectators" || roundEnded)){
    78.                 GUI.enabled = false;
    79.             }else{
    80.                 GUI.enabled = true;
    81.             }
    82.             if(GUILayout.Button(team_2.teamName)){
    83.                 //Kill current player if exist
    84.                 if(!Player){
    85.                     SpawnPlayer(team_2.teamName);
    86.                 }else{
    87.                     SwapTeams(team_2.teamName);
    88.                 }
    89.                 isPaused = false;
    90.                 //Player joined team, notify everyone
    91.                 gameObject.SendMessage("PlayerJoinedTeam", team_2.teamName, SendMessageOptions.DontRequireReceiver);
    92.             }
    93.         }else{
    94.             //Join game with Deathmatch mode
    95.             if(Player || (string)PhotonNetwork.player.customProperties["TeamName"] != "Spectators"){
    96.                 GUI.enabled = false;
    97.             }else{
    98.                 GUI.enabled = true;
    99.             }
    100.             if(GUILayout.Button("Join")){
    101.                 //Kill current player if exist
    102.                 if(!Player){
    103.                     SpawnPlayer(team_1.teamName);
    104.                 }else{
    105.                     SwapTeams(team_1.teamName);
    106.                 }
    107.                 isPaused = false;
    108.                 //Player joined team, notify everyone
    109.                 gameObject.SendMessage("PlayerJoinedTeam", "The War", SendMessageOptions.DontRequireReceiver);
    110.             }
    111.         }
    112.         GUI.enabled = true;
    113.         if(Player){
    114.             if(GUILayout.Button("Resume")){
    115.                 isPaused = false;
    116.             }
    117.         }
    118.         if(GUILayout.Button("Leave Room")){
    119.             LeaveRoom();
    120.         }
    121.         GUILayout.EndVertical();
    122.         GUILayout.EndHorizontal();
    123.         GUILayout.Space (10);
    124.         GUILayout.BeginHorizontal();
    125.         if(playerList){
    126.             GUI.color = new Color(0, 20, 0, 0.6f);
    127.         }else{
    128.             GUI.color = Color.white;
    129.         }
    130.         if(GUILayout.Button("Player List", GUILayout.Width(150), GUILayout.Height(25))){
    131.             playerList = true;
    132.         }
    133.         if(!playerList){
    134.             GUI.color = new Color(0, 20, 0, 0.6f);
    135.         }else{
    136.             GUI.color = Color.white;
    137.         }
    138.         if(GUILayout.Button("Controls", GUILayout.Width(150), GUILayout.Height(25))){
    139.             playerList = false;
    140.         }
    141.         GUILayout.EndHorizontal();
    142.         GUILayout.Space (5);
    143.         GUI.color = Color.white;
    144.         scroll3 = GUILayout.BeginScrollView(scroll3, GUILayout.Width(480), GUILayout.Height(300));
    145.         if(!playerList){
    146.             //Show controls
    147.             GUI.color = new Color(20, 20,0, 0.6f);
    148.             GUILayout.Label("Escape - Pause Menu");
    149.             GUILayout.Label("P - Fullscreen");
    150.             GUILayout.Label("T - Chat / Enter - send");
    151.             GUILayout.Label("C - crouch");
    152.             GUILayout.Label("Left Ctrl - prone");
    153.             GUILayout.Label("LMB - fire");
    154.             GUILayout.Label("RMB - aim");
    155.             GUILayout.Label("F - weapon pick up");
    156.             GUILayout.Label("R - reload");
    157.             GUILayout.Label("Left Shift - run");
    158.             GUILayout.Label("Space - jump");
    159.             GUILayout.Label("1/2 - weapon change");
    160.             GUILayout.Label("While selected STW-25 press G for flashlight");
    161.         }else{
    162.             //Show player list***
    163.             GUI.color = new Color(1,1,1,0.8f);
    164.             if(gameMode == "TDM"){
    165.                 //Display Team 1 **************************************************************************
    166.                 GUILayout.BeginHorizontal();
    167.                 GUILayout.FlexibleSpace();
    168.                 GUI.color = team_1_Color;
    169.                 GUILayout.Label(team_1.teamName);
    170.                 GUILayout.FlexibleSpace();
    171.                 GUILayout.EndHorizontal();
    172.                 foreach(PhotonPlayer player in allPlayers){
    173.                     if((string)player.customProperties["TeamName"] == team_1.teamName){
    174.                         if(PhotonNetwork.player.name == player.name){
    175.                             GUI.color = Color.yellow;
    176.                         }else{
    177.                             GUI.color = Color.white;
    178.                         }
    179.                         GUILayout.BeginHorizontal("box");{
    180.                             GUILayout.Label(player.name, GUILayout.Width(150));
    181.                             GUILayout.Label("Kills: " + ((int)player.customProperties["Kills"]).ToString(), GUILayout.Width(115));
    182.                             GUILayout.Label("Deaths: " + ((int)player.customProperties["Deaths"]).ToString(), GUILayout.Width(115));
    183.                             GUILayout.FlexibleSpace();
    184.                             if(player.customProperties["Ping"] != null){
    185.                                 GUILayout.Label("Ping: " + ((int)player.customProperties["Ping"]).ToString());
    186.                             }
    187.                             GUILayout.EndHorizontal();}
    188.                     }
    189.                 }
    190.                 //*************************************************************************************
    191.                 //Display Team 2 **************************************************************************
    192.                 GUILayout.BeginHorizontal();
    193.                 GUILayout.FlexibleSpace();
    194.                 GUI.color = team_2_Color;
    195.                 GUILayout.Label(team_2.teamName);
    196.                 GUILayout.FlexibleSpace();
    197.                 GUILayout.EndHorizontal();
    198.                 foreach(PhotonPlayer player in allPlayers){
    199.                     if((string)player.customProperties["TeamName"] == team_2.teamName){
    200.                         if(PhotonNetwork.player.name == player.name){
    201.                             GUI.color = Color.yellow;
    202.                         }else{
    203.                             GUI.color = Color.white;
    204.                         }
    205.                         GUILayout.BeginHorizontal("box");{
    206.                             GUILayout.Label(player.name, GUILayout.Width(150));
    207.                             GUILayout.Label("Kills: " + ((int)player.customProperties["Kills"]).ToString(), GUILayout.Width(115));
    208.                             GUILayout.Label("Deaths: " + ((int)player.customProperties["Deaths"]).ToString(), GUILayout.Width(115));
    209.                             GUILayout.FlexibleSpace();
    210.                             if(player.customProperties["Ping"] != null){
    211.                                 GUILayout.Label("Ping: " + ((int)player.customProperties["Ping"]).ToString());
    212.                             }
    213.                             GUILayout.EndHorizontal();}
    214.                     }
    215.                 }
    216.                 //*************************************************************************************
    217.             }else{
    218.                 //If game mode is Deathmatch, display all players **************************************************
    219.                 GUILayout.BeginHorizontal();
    220.                 GUILayout.FlexibleSpace();
    221.                 GUI.color = Color.green;
    222.                 GUILayout.Label("All Players");
    223.                 GUILayout.FlexibleSpace();
    224.                 GUILayout.EndHorizontal();
    225.                 foreach(PhotonPlayer player in allPlayers){
    226.                     if((string)player.customProperties["TeamName"] != "Spectators"){
    227.                         if(PhotonNetwork.player.name == player.name){
    228.                             GUI.color = Color.yellow;
    229.                         }else{
    230.                             GUI.color = Color.white;
    231.                         }
    232.                         GUILayout.BeginHorizontal("box");{
    233.                             GUILayout.Label(player.name, GUILayout.Width(150));
    234.                             GUILayout.Label("Kills: " + ((int)player.customProperties["Kills"]).ToString(), GUILayout.Width(115));
    235.                             GUILayout.Label("Deaths: " + ((int)player.customProperties["Deaths"]).ToString(), GUILayout.Width(115));
    236.                             GUILayout.FlexibleSpace();
    237.                             if(player.customProperties["Ping"] != null){
    238.                                 GUILayout.Label("Ping: " + ((int)player.customProperties["Ping"]).ToString());
    239.                             }
    240.                             GUILayout.EndHorizontal();}
    241.                     }
    242.                 }
    243.             }
    244.             //Display Spctators ****************************************************************************
    245.             GUILayout.BeginHorizontal();
    246.             GUILayout.FlexibleSpace();
    247.             GUI.color = Color.green;
    248.             GUILayout.Label("- Spectators -");
    249.             GUILayout.FlexibleSpace();
    250.             GUILayout.EndHorizontal();
    251.             foreach(PhotonPlayer player in allPlayers){
    252.                 if((string)player.customProperties["TeamName"] == "Spectators"){
    253.                     if(PhotonNetwork.player.name == player.name){
    254.                         GUI.color = Color.yellow;
    255.                     }else{
    256.                         GUI.color = Color.white;
    257.                     }
    258.                     GUILayout.BeginHorizontal("box");{
    259.                         GUILayout.Label(player.name);
    260.                         GUILayout.FlexibleSpace();
    261.                         if(player.customProperties["Ping"] != null){
    262.                             GUILayout.Label("Ping: " + ((int)player.customProperties["Ping"]).ToString());
    263.                         }
    264.                         GUILayout.EndHorizontal();}
    265.                 }
    266.             }
    267.             //*************************************************************************************
    268.         }
    269.         GUILayout.EndScrollView();
    270.     }
    271.     void  Resolutions(){
    272.         GUILayout.BeginVertical();
    273.         GUILayout.Label("Resolution");
    274.         scroll = GUILayout.BeginScrollView(scroll, GUILayout.Width(140), GUILayout.Height(100));
    275.         GUILayout.BeginVertical();
    276.         for(int a = 0; a < resolutions.Length; a++){
    277.             if(resolutions[a].width == Screen.width && resolutions[a].height == Screen.height){
    278.                 GUI.color = new Color(0, 20, 20, 0.6f);
    279.             }else{
    280.                 GUI.color = new Color(20, 20, 20, 0.6f);
    281.             }
    282.             if(GUILayout.Button(resolutions[a].width + " x " + resolutions[a].height)){
    283.                 resolutionIndex = a;
    284.                 if(Screen.fullScreen){
    285.                     Screen.SetResolution (resolutions[resolutionIndex].width,resolutions[resolutionIndex].height, true);
    286.                 }
    287.             }
    288.         }
    289.         GUILayout.EndVertical();
    290.         GUILayout.EndScrollView();
    291.         GUILayout.EndVertical();
    292.     }
    293.     void QualityWindow(){
    294.         //GUILayout.Space (10);
    295.         GUILayout.BeginVertical();
    296.         GUI.color = Color.white;
    297.         GUILayout.Label("Quality");
    298.         scroll2 = GUILayout.BeginScrollView(scroll2, GUILayout.Width(140), GUILayout.Height(100));
    299.         GUILayout.BeginVertical();
    300.         for (var i = 0; i < QualityNames.Length; i++){
    301.             if(QualityNames[i] == QualityNames[QualitySettings.GetQualityLevel ()]){
    302.                 GUI.color = new Color(0, 20, 20, 0.6f);
    303.             }else{
    304.                 GUI.color = new Color(20, 20, 20, 0.6f);
    305.             }
    306.             if (GUILayout.Button (QualityNames[i]))
    307.                 QualitySettings.SetQualityLevel (i, true);
    308.         }
    309.         GUILayout.EndVertical();
    310.         GUILayout.EndScrollView();
    311.         GUILayout.EndVertical();
    312.     }
    313.     void FadeScreen(){
    314.         if(fadeDir == 1){
    315.             fadeValue += fadeDir * 15 * Time.deltaTime;
    316.             fadeValue = Mathf.Clamp01(fadeValue);
    317.             GUI.color = new Color(1,1,1,fadeValue);
    318.             GUI.DrawTexture(new Rect(0,0, Screen.width, Screen.height), blackScreen);
    319.             GUI.color = Color.white;
    320.             GUI.Label(new Rect(Screen.width/2 - 75, Screen.height/2 - 15, 150, 30), "Loading...");
    321.         }
    322.     }

    And this is how i see my pause menu:


     

    Attached Files:

  2. uDamian

    uDamian

    Unity Technologies

    Joined:
    Dec 11, 2017
    Posts:
    1,231
  3. FedeStefan

    FedeStefan

    Joined:
    Aug 15, 2018
    Posts:
    221