Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

ArgumentException: Getting control 1's position in a group with only 1 control

Discussion in 'Immediate Mode GUI (IMGUI)' started by abelreyes, Feb 9, 2016.

  1. abelreyes

    abelreyes

    Joined:
    Sep 11, 2013
    Posts:
    28
    Hey there,
    I'm Abel, the developer of Derepent.com and i'm working on a new editor extension for unity that notifies the following error:
    ArgumentException: Getting control 1's position in a group with only 1 controls when doing mouseUp

    The error is being caused by a toggle button I've created:


    Code (CSharp):
    1.         EditorGUILayout.BeginVertical ();
    2.         {
    3.             EditorGUILayout.BeginHorizontal (foldoutBox); //<- Main button
    4.             {
    5.                 //Some useless code
    6.             }
    7.             EditorGUILayout.EndHorizontal ();
    8.  
    9.             if (Event.current.type == EventType.mouseUp && GUILayoutUtility.GetLastRect ().Contains (Event.current.mousePosition)) { //Get mouseUp (click) over "MainButton"
    10.                 type.openedInEditor = !type.openedInEditor; //<- Line Causing error
    11.                 this.Repaint ();
    12.             }
    13.  
    14.             if (type.openedInEditor) { //<- Line causing error, it seems the error is notified when showing this GUI element
    15.                 GUI.backgroundColor = new Color (0.94f, 0.94f, 0.94f);
    16.                 EditorGUILayout.BeginVertical (foldoutSubBox); //<- Custom list
    17.                 {
    18.                     ObjectTable (type.objects, type, false);
    19.                 }
    20.                 EditorGUILayout.EndVertical ();
    21.                 GUI.backgroundColor = Color.white;
    22.             }
    23.         }
    24.         EditorGUILayout.EndVertical ();
    As comented on the code, it seems that the error is caused when showing "Custom list" element (see comments), but the code is working properly even with that error. Anyone knows why is this happening?

    Thank you, Abel!

    EDIT:
    I've found a solution, but i don't know if it's the best:
    Before calling window Repaint(), i'm setting current event type to used (Event.current.Use()), and the error is not being displayed anymore...
     
    Last edited: Feb 9, 2016
  2. Seneral

    Seneral

    Joined:
    Jun 2, 2014
    Posts:
    1,206
    You can take a look at this thread, it has a good explanation why this occurs. The solution won't work for you though, since it's an editor scipt. I've had this problem multiple times, too. It's really nasty, but you basically have to make sure the layouting process as described in the link isn't interrupted. You can do that by waiting until the repaint event before setting type.openedInEditor. This does require a seperate variable though, but again I've not found a better way yet:(
     
    abelreyes likes this.
  3. abelreyes

    abelreyes

    Joined:
    Sep 11, 2013
    Posts:
    28
    I've arrived to that post also, but even knowing how the GUI work i can't find a way to make it prettier... But thanks, I'll be trying a little bit more!