- Home /
ArgumentException: Getting control 0's position in a group with only 0 controls when doing Repaint. Mysterious Window? Script breaking? Why?
So, I am making a spaceship game with a fitting window. The script includes 2 windows: The ship stats (Which include all of the ship stats and hardpoints, and a gun fitting window which is brought up when the user clicks a hardpoint button. The script then works with another script to instantiate gameObjects when items are fitted.
What doesn't work: I get a mysterious, "ArgumentException: Getting control 0's position in a group with only 0 controls when doing Repaint" This causes the fitting buttons to not select their element out of their array correctly. and a random window is drawn out of the middle of nowhere, maybe connected to the error, despite only having 2 window drawn functions in the entire script(s).
Help is much appreciated.
Script 1 (goes in gameobject in scene)
public class fittingScript : Photon.MonoBehaviour {
//Remember to change the unfit id to 20 if exceeding 10 turrets
public bool isEditor = true;
private Vector2 scrollPosition = new Vector2(300,300);
private Rect subWindowRect = new Rect(10,Screen.height / 5 * 3 + 10,Screen.width / 5 * 2 - 20, Screen.height/5 * 2 - 20);
private Rect statsRect = new Rect(Screen.width/5 * 4 - 20, 10, Screen.width/5 - 20, Screen.height/5 * 2 - 20);
public hardpointInitialization[] hardpoints; //How we find our hardpoints. Hardpoints must contain this to be recognized.
private hardpointInitialization selectedPoint; //The currently selected point.
private int currentlySelectedItem = 0;
//Ship Stats For Saving and Fitting
public string ship = "";
public float power = 0.0f;
public float maxPower = 100.0f;
public float detection = 100.0f;
public float speed = 0.0f;
public float maxHp = 0.0f;
// Use this for initialization
void Start () {
hardpoints = new hardpointInitialization[GetComponentsInChildren<hardpointInitialization>().Length];
hardpoints = GetComponentsInChildren<hardpointInitialization>();
Debug.Log(hardpoints);
//Do all the turret instantiation and locking here.
}
void Update () {
}
// Update is called once per frame
void OnGUI () {
GUI.Window(2,statsRect,shipInfoWindow,"Ship Stats");
GUI.Window(1,subWindowRect,selectedGunWindow,"Selected Slot");
}
//BELOW IS EDITOR FUNCTIONS
//--------------------------------------------------------------------------------------------------
void selectedGunWindow(int id) {
//The item database is stored here!
if (selectedPoint == null) {
return;
}
GUILayout.BeginHorizontal();
if (GUILayout.Button("<")) {
currentlySelectedItem--;
}
switch(currentlySelectedItem) {
case 0:
GUILayout.Label("X-4 Heavy Railgun Double");
break;
case 1:
GUILayout.Label("X-2 Saron Laser Double");
break;
case 2:
GUILayout.Label("L-32 Flyswatter");
break;
}
if (GUILayout.Button(">")) { //Make the item selection go up
currentlySelectedItem++;
}
GUILayout.EndHorizontal();
scrollPosition = GUILayout.BeginScrollView(scrollPosition,GUILayout.Width (Screen.width/5*2),GUILayout.Height(100));
switch(currentlySelectedItem) {
case 0:
GUILayout.TextArea("This is a heavy railgun double. Nothin special... YET!",GUILayout.Width(Screen.width/5 * 2-40));
break;
case 1:
GUILayout.TextArea(" Stuff about this gun",GUILayout.Width(Screen.width/5 * 2-40));
break;
case 2:
GUILayout.TextArea(" Stuff about this gun",GUILayout.Width(Screen.width/5 * 2-40));
break;
}
GUILayout.EndScrollView();
currentlySelectedItem = Mathf.Clamp(currentlySelectedItem,0,2);
if(GUILayout.Button("Fit")) {
//TODO add checks for power, calibration etc.
switch(currentlySelectedItem) {
case 0:
selectedPoint.itemName = "turret_HeavyRailgunDouble";
selectedPoint.itemId = 0;
//ITEM STATISTICS!
//--------------------------------
selectedPoint.editorChange ();
//TODO edit power and stuff.
break;
case 1:
selectedPoint.itemName = "turret_SaronDouble";
selectedPoint.itemId = 1;
//ITEM STATISTICS!
//--------------------------------
selectedPoint.editorChange ();
break;
case 2:
selectedPoint.itemName = "turret_FlySwatter";
selectedPoint.itemId = 2;
//ITEM STATISTICS!
//--------------------------------
selectedPoint.editorChange ();
break;
}
}
}
/// <summary>
/// Ships the info window.
/// </summary>
/// <param name="id">Identifier.</param>
void shipInfoWindow (int id) {
GUILayout.Label("Ship: " + ship);
if (power > maxPower) {
GUI.contentColor = Color.red;
GUILayout.Label("Power: (" + power.ToString() + " GW/" + maxPower.ToString() + " GW)");
GUI.contentColor = Color.white;
}
else {
GUILayout.Label("Power: (" + power.ToString() + " GW/" + maxPower.ToString() + " GW)");
}
GUILayout.Label("Detection :" + detection.ToString() + " U");
GUILayout.Label("Speed: " + speed.ToString() + " U/second");
GUILayout.Label("Hardpoints");
foreach(hardpointInitialization hp in hardpoints) {
GUILayout.Button("|" + hp.itemId + "|");
selectedPoint = hp;
}
}
}
script 2 ( multiple of these go in gameobjects childed of the gameobject the above script is in
public int hardpointType = 0; //0 = turret, 1 = Utility, 2 = Capital.
public string itemName = "None"; //This is used for identifying the item the hardpoint has. Will be updated via script.
public int itemId = 0; //This is the more explicit way of doing things.
public bool isEnabled = false;
public GameObject currentTurret = null;
public GameObject currentTurretInEditor = null;
public fittingScript editor;
public GameObject[] turretModels;
public float powerRequirement = 0.0f;
public float speedPenalty = 0.0f;
public float stealthPenalty = 0.0f;
void Start () {
if (!isEnabled) {
currentTurret = PhotonNetwork.Instantiate(itemName,transform.position,transform.rotation,0);//What this does is that it creates the turret TODO Test it.
currentTurret.transform.parent = gameObject.transform; //Then locks it in place. This is all according to the fitting menu TODO make it according to fitting menu.
}
}
void Update () {
}
public void editorChange () {
if (!isEnabled) {
return;
}
if(currentTurretInEditor != null) {
GameObject.Destroy(currentTurretInEditor);
powerRequirement = 0f;
speedPenalty = 0f;
stealthPenalty = 0f;
}
switch (itemId) {
case 0:
currentTurretInEditor = GameObject.Instantiate(turretModels[0],transform.position,transform.rotation) as GameObject; //Heavy Double Railgun
currentTurretInEditor.transform.parent = gameObject.transform;
powerRequirement = 30f;
speedPenalty = 1f;
break;
case 1:
currentTurretInEditor = GameObject.Instantiate(turretModels[1],transform.position,transform.rotation) as GameObject; //Saron Double
currentTurretInEditor.transform.parent = gameObject.transform;
powerRequirement = 25f;
speedPenalty = 1f;
break;
case 2:
currentTurretInEditor = GameObject.Instantiate(turretModels[2],transform.position,transform.rotation) as GameObject; //Flyswatter
currentTurretInEditor.transform.parent = gameObject.transform;
powerRequirement = 20f;
speedPenalty = 0f;
break;
case 10:
Debug.Log("Nothing!");
break;
}
}
}
Your answer
Follow this Question
Related Questions
How do i get size in pixels of a GUI.Label for chat construction purpose ? 2 Answers
EditorGUI, EditorGUILayout, GUI, GUILayout... pshhh... WHEN TO USE WHAT?! 3 Answers
EditorGUI like light explorer window 1 Answer
Drawing several BeginArea inside a BeginScrollview (GUILayout) produces an unexpected behaviour 1 Answer
Why do my GUI Layout Buttons not appear on screen? 0 Answers