• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by Projimmothy · Aug 20, 2014 at 02:46 PM · errorcharacterargumentexception

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

I am getting the error GUI Error: You are pus$$anonymous$$ng more GUIClips than you are popping. Make sure they are balanced) and the error ArgumentException: The prefab you want to instantiate is null. UnityEngine.Object.CheckNullArgument (System.Object arg, System.String message) (at C:/BuildAgent/work/d63dfc6385190b60/artifacts/EditorGenerated/UnityEngineObject.cs:104) UnityEngine.Object.Instantiate (UnityEngine.Object original, Vector3 position, Quaternion rotation) (at C:/BuildAgent/work/d63dfc6385190b60/artifacts/EditorGenerated/UnityEngineObject.cs:83) PC.get_Instance () (at Assets/Scripts/Character/PC.cs:20) CharacterGenerator.DisplayName () (at Assets/Scripts/Character/CharacterGenerator.cs:94) CharacterGenerator.MyWindow (Int32 id) (at Assets/Scripts/Character/CharacterGenerator.cs:79) UnityEngine.GUI.CallWindowDelegate (UnityEngine.WindowFunction func, Int32 id, UnityEngine.GUISkin _skin, Int32 forceRect, Single width, Single height, UnityEngine.GUIStyle style) (at C:/BuildAgent/work/d63dfc6385190b60/artifacts/EditorGenerated/GUI.cs:1402)

T$$anonymous$$s is the script I have attached to my main camera.

 /// <summary>
 /// CharacterGenerator.cs
 /// Aug 19, 2014
 /// Uncle Jimz
 /// 
 /// T$$anonymous$$s script is used to help the user generate a character.
 /// 
 using UnityEngine;
 using System.Collections;
 using System;                    //used for the Enum class
 
 public class CharacterGenerator : MonoBehaviour {
 //    private PlayerCharacter _toon;
     private const int STARTING_POINTS = 350;
     private const int MIN_STARTING_ATTRIBUTE_VALUE = 10;
     private const int STARTING_VALUE = 50;
     private int pointsLeft;
     
     private const int OFFSET = 5;
     private const int LINE_HEIGHT = 32;
     
     private const int STAT_LABEL_WIDTH = 200;
     private const int BASEVALUE_LABEL_WIDTH = 90;
     private const int BUTTON_WIDTH = 60;
     private const int BUTTON_HEIGHT = 32;
     
     private Rect windowRect;
     
     private int statStartingPos = 30;
     
     public GUISkin mySkin;
     
     public float delayTimer = .25f;
     private float _lastClick = 0;
     
     void Awake() {
 //        Debug.Log("***CharacterGenerator - Awake***");
 //        PC.Instance.Initialize();
     }
     
     // Use t$$anonymous$$s for initialization
     void Start () {
 //        Debug.Log("***CharacterGenerator - Start***");
         
         pointsLeft = STARTING_POINTS;
         
         for(int cnt = 0; cnt < Enum.GetValues(typeof(AttributeName)).Length; cnt++) {
             PC.Instance.GetPrimaryAttribute(cnt).BaseValue = STARTING_VALUE;
             pointsLeft -= (STARTING_VALUE - MIN_STARTING_ATTRIBUTE_VALUE);    
         }
 
         PC.Instance.StatUpdate();
     }
         
     //update the GUI
     void OnGUI() {
         GUI.skin = mySkin;
         
         windowRect = GUI.Window( 0, windowRect, MyWindow, "Character Creation" );
         
 //        if(_toon.Name == "" || pointsLeft > 0)
 //            DisplayCreateLabel();
 //        else
 //            DisplayCreateButton();
     }
     
     public void Update() {
         windowRect    = new Rect( -5, -23, Screen.width + 10, Screen.height + 46 );
     }
     
     
     private void MyWindow( int id ) {
         DisplayName();
         DisplayPointsLeft();
         DisplayAttributes();
         DisplayVitals();
         DisplaySkills();
 
         if(PC.Instance.name != "" && pointsLeft < 1)
             DisplayCreateButton();
 
     }
     
     //display the name lable as well as the textbox for them to enter the name
     private void DisplayName() {
         GUI.BeginGroup( new Rect( 40, 90, 400, LINE_HEIGHT ) );
             GUI.Label(new Rect( 0, 0, 120, LINE_HEIGHT), "Name:");
             PC.Instance.name = GUI.TextField(new Rect(120, 0, 200, LINE_HEIGHT), PC.Instance.name);
         GUI.EndGroup();
     }
     
     //display all of the attributes as well as the +/- boxes for the user to alter the values
     private void DisplayAttributes() {
         GUI.BeginGroup(new Rect( 40, 90 + LINE_HEIGHT, ( Screen.width - 80 ) / 2, LINE_HEIGHT * ( Enum.GetValues(typeof(AttributeName)).Length + 1 ) ), "Attributes", "box" );
         for(int cnt = 0; cnt < Enum.GetValues(typeof(AttributeName)).Length; cnt++) {
             GUI.Label(new Rect(    OFFSET,                                    //x
                                 statStartingPos + (cnt * LINE_HEIGHT),    //y
                                 STAT_LABEL_WIDTH,                        //width
                                 LINE_HEIGHT                                //height
                     ), ((AttributeName)cnt).ToString());
 
             GUI.Label(new Rect(    STAT_LABEL_WIDTH + OFFSET,                //x
                                 statStartingPos + (cnt * LINE_HEIGHT),    //y
                                 BASEVALUE_LABEL_WIDTH,                    //width
                                 LINE_HEIGHT                                //height
                      ), PC.Instance.GetPrimaryAttribute(cnt).AdjustedBaseValue.ToString());
 
             if(GUI.RepeatButton(new Rect(    OFFSET + STAT_LABEL_WIDTH + BASEVALUE_LABEL_WIDTH,    //x
                                     statStartingPos + (cnt * BUTTON_HEIGHT),            //y
                                     BUTTON_WIDTH,                                        //width
                                     BUTTON_HEIGHT                                        //height
                          ), "-")) {
                 
                 if(Time.time - _lastClick > delayTimer) {
                     if(PC.Instance.GetPrimaryAttribute(cnt).BaseValue > MIN_STARTING_ATTRIBUTE_VALUE) {
                         PC.Instance.GetPrimaryAttribute(cnt).BaseValue--;
                         pointsLeft++;
                         PC.Instance.StatUpdate();
                     }
                     _lastClick = Time.time;
                 }
             }
             if(GUI.RepeatButton(new Rect( OFFSET + STAT_LABEL_WIDTH + BASEVALUE_LABEL_WIDTH + BUTTON_WIDTH,    //x
                                     statStartingPos + (cnt * BUTTON_HEIGHT),                            //y
                                     BUTTON_WIDTH,                                                        //width
                                     BUTTON_HEIGHT                                                        //height
                          ), "+")) {
                 
                 if(Time.time - _lastClick > delayTimer) {
                     if(pointsLeft > 0) {
                         PC.Instance.GetPrimaryAttribute(cnt).BaseValue++;
                         pointsLeft--;
                         PC.Instance.StatUpdate();
                     }
                     _lastClick = Time.time;
                 }
             }
         }
         GUI.EndGroup();
     }
     
     //display all of the vitals
     private void DisplayVitals() {
         GUI.BeginGroup(new Rect( 40, 90 + LINE_HEIGHT * (Enum.GetValues(typeof(AttributeName)).Length + 2), ( Screen.width - 80 ) / 2, LINE_HEIGHT * ( Enum.GetValues(typeof(VitalName)).Length + 1 ) ), "Vitals", "box" );
         for(int cnt = 0; cnt < Enum.GetValues(typeof(VitalName)).Length; cnt++) {
             GUI.Label(new Rect( OFFSET,                                            //x
                                 statStartingPos + (cnt * LINE_HEIGHT),            //y
                                 STAT_LABEL_WIDTH,                                //width
                                 LINE_HEIGHT                                        //height
                      ), ((VitalName)cnt).ToString());
             
             GUI.Label(new Rect( OFFSET + STAT_LABEL_WIDTH,                        //x
                                 statStartingPos + (cnt * LINE_HEIGHT),            //y
                                 BASEVALUE_LABEL_WIDTH,                            //width
                                 LINE_HEIGHT                                        //height
                      ), PC.Instance.GetVital(cnt).AdjustedBaseValue.ToString());
         }
         GUI.EndGroup();
     }    
     
     //display all of the skills
     private void DisplaySkills() {
         GUI.BeginGroup(new Rect( Screen.width - ( Screen.width - 20 ) / 2, 90 + LINE_HEIGHT, ( Screen.width - 80 ) / 2, LINE_HEIGHT * ( Enum.GetValues(typeof(SkillName)).Length + 1 ) ), "Attributes", "box" );
         for(int cnt = 0; cnt < Enum.GetValues(typeof(SkillName)).Length; cnt++) {
             GUI.Label(new Rect( 0,    //x
                                 statStartingPos + (cnt * LINE_HEIGHT),                                                //y
                                 STAT_LABEL_WIDTH,                                                                    //width
                                 LINE_HEIGHT                                                                            //height
                      ), ((SkillName)cnt).ToString());
 
             GUI.Label(new Rect( STAT_LABEL_WIDTH,    //x
                                 statStartingPos + (cnt * LINE_HEIGHT),                                                                    //y
                                 BASEVALUE_LABEL_WIDTH,                                                                                    //width
                                 LINE_HEIGHT                                                                                                //height
                      ), PC.Instance.GetSkill(cnt).AdjustedBaseValue.ToString());
         }
         GUI.EndGroup();
     }
     
     //show them how many points they have left to spend
     private void DisplayPointsLeft() {
         GUI.Label(new Rect(Screen.width - 150 - 30, 90, 150, LINE_HEIGHT), "Points Left: " + pointsLeft.ToString());
     }
     
     //display label that looks like a button until they have all the requiements filled out to create a character
     private void DisplayCreateLabel() {
 //        GUI.Label(new Rect( Screen.width/ 2 - 50, statStartingPos + (10 * LINE_HEIGHT), 100, LINE_HEIGHT), "Creating...", "Button");
     }
 
     //display the button that will call the save method when pressed, and then load the first level
     private void DisplayCreateButton() {
         if(GUI.Button(new Rect( Screen.width/ 2 - 50, statStartingPos + (10 * LINE_HEIGHT), 100, LINE_HEIGHT), "Next")) {
             //change the cur value of the vitals to the max modified value of that vital
             UpdateCurVitalValues();
             
             GameSetting2.SaveName( PC.Instance.name );
             GameSetting2.SaveAttributes( PC.Instance.primaryAttribute );
             GameSetting2.SaveVitals( PC.Instance.vital );
             GameSetting2.SaveSkills( PC.Instance.skill );
 
             Application.LoadLevel(GameSetting2.levelNames[2]);
         }
     }
     
     //update the curValue for each vital to be the max value it can be so we do not start with a  zero in any vital
     private void UpdateCurVitalValues() {
         for(int cnt = 0; cnt < Enum.GetValues(typeof(VitalName)).Length; cnt++) {
             PC.Instance.GetVital(cnt).CurValue = PC.Instance.GetVital(cnt).AdjustedBaseValue;
         }
     }
 }
 

Comment
yektasarioglu

People who like this

1 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

5 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Cherno · Aug 20, 2014 at 02:58 PM

T$$anonymous$$s has most likely to do with a GUI function not closing properly; T$$anonymous$$ngs like GUI.BeginScrollView, GUI Groups and such need corresponding "End" lines of codes. Comment out all GUI functions and de-comment them one by one, and see w$$anonymous$$ch one has no end.

Comment
metroidsnes
FeenikxFire
RukshanJSenanayaka

People who like this

3 Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Projimmothy · Aug 20, 2014 at 03:02 PM 0
Share

Cherno,

I am still getting used to using Unity so can you please explain what you mean?

avatar image Cherno · Aug 20, 2014 at 03:18 PM 0
Share

Of course!

Each time you use GUI.BeginGroup, you also have to use GUI.EndGroup() in the same function. It works like parentheses (), so they can be nested like ((())), but every start has to have and end.

You can comment out code with

 /*
 
 code bit to be commented out
 
 */


and

 //line of code to be commented out

to deactive parts of your code, and find the error part.

avatar image Projimmothy · Aug 20, 2014 at 03:26 PM 0
Share

When I took out all of the GUI Groups, it stopped the GUI error but there is still this error..... ArgumentException: The prefab you want to instantiate is null. UnityEngine.Object.CheckNullArgument (System.Object arg, System.String message) (at C:/BuildAgent/work/d63dfc6385190b60/artifacts/EditorGenerated/UnityEngineObject.cs:104) UnityEngine.Object.Instantiate (UnityEngine.Object original, Vector3 position, Quaternion rotation) (at C:/BuildAgent/work/d63dfc6385190b60/artifacts/EditorGenerated/UnityEngineObject.cs:83) PC.get_Instance () (at Assets/Scripts/Character/PC.cs:20) CharacterGenerator.MyWindow (Int32 id) (at Assets/Scripts/Character/CharacterGenerator.cs:79) UnityEngine.GUI.CallWindowDelegate (UnityEngine.WindowFunction func, Int32 id, UnityEngine.GUISkin _skin, Int32 forceRect, Single width, Single height, UnityEngine.GUIStyle style) (at C:/BuildAgent/work/d63dfc6385190b60/artifacts/EditorGenerated/GUI.cs:1402)

avatar image Cherno · Aug 20, 2014 at 03:29 PM 0
Share

Double click on the error message in the console and it takes you to the offending line in question.

It is probably this one, which I have no idea what it does:

  PC.Instance.GetPrimaryAttribute(cnt).BaseValue = STARTING_VALUE;

avatar image Projimmothy · Aug 20, 2014 at 03:43 PM 0
Share

WOW I had no idea you could do that! That seems to have fixed all errors. Thank you so much for your tyme!

Show more comments
avatar image

Answer by ClockworkBeetle · Apr 22, 2021 at 10:48 AM

For anyone else viewing t$$anonymous$$s, I got t$$anonymous$$s exact error and had never changed anyt$$anonymous$$ng that should have anyt$$anonymous$$ng to do with any of t$$anonymous$$s. Restarted Unity not once, but twice, and the error disappeared :D

Comment
pKallv
efge
yektasarioglu
Riiich
ow3n

People who like this

5 Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image pKallv · Oct 29, 2021 at 09:22 PM 1
Share

Thanks. I just needed to restart once for it to disappear.

avatar image efge · Nov 26, 2021 at 12:32 PM 0
Share

Still necessary with 2021.2.4

avatar image Riiich · Jan 25, 2022 at 11:11 PM 0
Share

Still works in 2022

avatar image AliBuck · Feb 16 at 09:14 PM 0
Share

was the case for me!) Arigatou!)

avatar image

Answer by Tushar98 · Jun 13, 2020 at 06:19 AM

@Projimmothy I know it is late for reply, but still. For those who are viewing it now, I was getting the same error. I was loading 2 audio clips in a function and calling it in my GUIOperation() Function from Update method in my script, so it was giving me t$$anonymous$$s error. I solved t$$anonymous$$s error by calling my GUIOperation() Function from FixedUpdate function. Like t$$anonymous$$s:
public void FixedUpdate() { GUIOperation(); }

Hope it helps.

Comment
PedroD015
Riiich
Deidall

People who like this

3 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

Answer by duartejuca · Aug 23, 2022 at 09:19 PM

go to C:\Users\$USER_NAME_FOLDER\AppData\LocalLow\DefaultCompany and delete the project folder with your project name.

T$$anonymous$$s works for me.

Best Regards

Comment
Dance_M

People who like this

1 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

Answer by wiredninja · Apr 07, 2022 at 07:12 PM

I had that error, because I made a CustomEditor and had its class declared abstract.

Comment

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Background & sprites are smearing towards the player during movement. Help determine the cause and solution? 0 Answers

Instantiate in a class 1 Answer

problem in database connection 2 Answers

Player sinking into walls and floor with Raycasts 1 Answer

BindSkin:cannot find transform 'FLOOR' 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges