Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by Daftcube · Apr 28, 2014 at 03:00 PM · guiforeachguilayoutgui.window

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;
         }
     }
 }
 
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

0 Replies

· Add your reply
  • Sort: 

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

21 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


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