- Home /
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;
}
}
}
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.
Cherno,
I am still getting used to using Unity so can you please explain what you mean?
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.
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)
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;
WOW I had no idea you could do that! That seems to have fixed all errors. Thank you so much for your tyme!
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
Thanks. I just needed to restart once for it to disappear.
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.
Answer by wiredninja · Apr 07 at 07:12 PM
I had that error, because I made a CustomEditor and had its class declared abstract.
Your answer
Follow this Question
Related Questions
What exactly this error is trying to inform me about? 1 Answer
Base Character error 1 Answer
Third person controller error in line 333 and 337 1 Answer
Cannot build for Windows Store Apps because of 'Invalid Characters in Path' 0 Answers
GUI Error: You are pushing more GUIClips than you are popping. Make sure they are balanced) 2 Answers