Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 Jun 22
sparklines
Close Help
  • 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
1
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 pushing 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)

This is the script I have attached to my main camera.

 /// <summary>
 /// CharacterGenerator.cs
 /// Aug 19, 2014
 /// Uncle Jimz
 /// 
 /// This 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 this 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
Add comment
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

4 Replies

· Add your reply
  • Sort: 
avatar image
3
Best Answer

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

This has most likely to do with a GUI function not closing properly; Things 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 which one has no end.

Comment
Add comment · 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.$$anonymous$$yWindow (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
5

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

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

Comment
Add comment · Show 3 · 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 at 11:11 PM 0
Share

Still works in 2022

avatar image
2

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 this error. I solved this error by calling my GUIOperation() Function from FixedUpdate function. Like this:
public void FixedUpdate() { GUIOperation(); }

Hope it helps.

Comment
Add comment · 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
0

Answer by wiredninja · Apr 07 at 07:12 PM

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

Comment
Add comment · 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.

Follow this Question

Answers Answers and Comments

9 People are following this question.

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

Related Questions

Build Fails In Unity 3.0 4 Answers

ArgumentException: Object of type 'UnityEngine.Object' cannot be converted to type 'UnityEngine.GameObject'. 0 Answers

Null reference exception error in Unity, Please Help! 1 Answer

ArgumentOutOfRangeException when trying to create prefab torpedo shots (Bullets) 1 Answer

Object reference not set to an instance of an Object 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