- Home /
 
ArgumentException: Getting control 1's position...
"ArgumentException: Getting control 1's position in a group with only 1 controls when doing Repaint"
I've searched this error and found many responses; however, the solutions some people have given have just gone over my head on how I can adapt it to my code.
A littler premise, I've been trying to create draggable window panes to create a visual Icon Represented Map Editor in Unity, and ultimately extend it to create a simple script editor for creating interactions with NPCs and entities in a game. My issue arose when I tried to stylize some buttons.
I'm gonna post some of my code.
[A WindowPane Controller] public class TAGWindowController : ScriptableObject {
     bool f_Scrollable = false; //when no window is selected ina  drag, will a drag move every window?
 
     Vector2 m_MouseOffset; //the offset the mouse was from the origin of the window
     Vector2 m_LastMousePos; //last known position of the mouse.  Used for scrolling
 
     List<TAGWindow> m_Panels = new List<TAGWindow>();
     TAGWindow m_DraggedPanel = null;    //Which window is currently being dragged
     TAGWindow m_MouseOverPanel = null;        //Which window is the mouse hovering over
     TAGWindow m_FocusedPanel = null;    //Which window is selected and focused
 
     int m_NextWindowID = 0;
 
     public void OnEnable()
     {
     }
 
 
 
     public void OnGUI()
     {
         Event e = Event.current;
         
         
         if(e.type == EventType.Repaint)
         {
         }
 
         //Reset what the mouse is over, in case it has changed
         if(m_MouseOverPanel != null)
         {
             m_MouseOverPanel.Hover = false;
 
             m_MouseOverPanel = null;
         }
 
         //Find the top most window the mouse is over
         for(int i=0; i< m_Panels.Count; i++)
         {
             //if(m_Panels[i].Contains(e.mousePosition))
             //    m_Panels[i].Hover = true;
             if(m_Panels[i].Contains(e.mousePosition))
             {
                 m_MouseOverPanel = m_Panels[i];
             }
         }
 
         //If the mouse is found over a panel, set the panel's Hover mode to true;
         if(m_MouseOverPanel!= null)
             m_MouseOverPanel.Hover = true;
         
         if(e.isMouse)
         {
             if(e.button == 0) //Left Mouse Button Selects Pane
             {
                 if(e.type == EventType.MouseDown)
                 {
                     if(m_MouseOverPanel != null)
                     {
                         m_FocusedPanel = m_MouseOverPanel;
                         m_DraggedPanel = m_MouseOverPanel;
                         m_MouseOffset = m_DraggedPanel.Position - e.mousePosition;
 
                         m_FocusedPanel.Selected = true;
                         MovePaneToTop(m_FocusedPanel);
                     }
                 }else if(e.type == EventType.MouseUp)
                 {
                     m_DraggedPanel = null;
                     //m_scrolling = false;
                     
                 }else if(e.type == EventType.MouseDrag)
                 {
                     if(m_DraggedPanel != null)
                     {
                         m_DraggedPanel.Position = e.mousePosition + m_MouseOffset;
                     }
                 }
             }else if(e.button == 1) //Right Mouse Button scrolls pane
             {
                 if(e.type == EventType.MouseDown)
                 {
                     m_LastMousePos = e.mousePosition;
                 }else if(e.type == EventType.MouseUp)
                 {
                 }else if(e.type == EventType.MouseDrag)
                 {
                     Vector2 drag = e.mousePosition - m_LastMousePos;
                     m_LastMousePos = e.mousePosition;
                     for(int i=0;i<m_Panels.Count;i++)
                     {
                         m_Panels[i].Translate(drag);
                     }
                 }
             }
 
         }
         
         for(int i=0; i< m_Panels.Count; i++)
         {
             m_Panels[i].OnGUI();
         }
 
     }
 
     public void AddWindow(TAGWindow newWindow)
     {
         newWindow.ID = m_NextWindowID++;
         m_Panels.Add(newWindow);
     }
 
     public bool Scrollable
     {
         get{
             return f_Scrollable;
         }
         set{
             f_Scrollable = value;
         }
     }
 
     public void MovePaneToTop(TAGWindow pane)
     {
         m_Panels.Remove(pane);
         m_Panels.Add(pane);
     }
 }
 
               TAGWindow is the base class my window panes extend from public class TAGWindow : ScriptableObject {
     //public enum MouseStatusTypes{None = 0, Hover, Selected};
 
     Rect m_WindowRect = new Rect(0,0,0,0);
     Rect m_DragRect; //a position on the window that allows the window to be dragged
 
     int m_ID = -1;
 
     bool m_MouseOver = false;  //is the mouse hovering over the window
 
     //bool m_enabled = true; // is the WIndow enabled;
     bool m_Dragging = false; // is the window currently being dragged
     bool m_Focused = false;
     bool m_Selected = false;
 
     //MouseStatusTypes f_MouseStatus;
     //Getters and setters shortened for the posting
     public Vector2 Position
     public Vector2 Size
     public Rect WindowRect
     public Rect DragRect
     public bool Dragging
     public bool Focused
     public bool Hover
     public int ID
     public bool Selected
     public bool Contains(Vector2 point)
     {
         return m_WindowRect.Contains(point);
     }
 
     public bool PointInDragRect(Vector2 point)
     {
         return m_DragRect.Contains(point);
     }
 
     public void Translate(Vector2 shift) //shift the window by Vector2
     {
         m_WindowRect.position += shift;
     }
 
     public virtual void OnGUI()
     {
         Debug.Log ("A Window's OnGUI was not overriden");
     }
 
     public virtual void OnUpdate()
     {
         Debug.Log ("A Window's OnUpdate was not overriden");
     }
 }
 
               And Finally, the main class that pieces it all together, with a custom window extending TAGWindow public class TAGMapEditor : EditorWindow {
     bool doRepaint = false;
 
     Dictionary<int,TAGWindow> Rooms = new Dictionary<int,TAGWindow>();
 
     TAGWindowController panes = CreateInstance<TAGWindowController>();
 
 
     [MenuItem("UTAG/Map Editor")]
     public static void Init()
     {
         GetWindow (typeof(TAGMapEditor)).Show ();
     }
 
     public void OnEnable()
     {
 
         RoomIcon t = CreateInstance<RoomIcon>();
         t.WindowRect = new Rect(20,20,100,100);
         t.parent = this;
         panes.AddWindow(t);
 
         t = CreateInstance<RoomIcon>();
         t.WindowRect = new Rect(20,200,200,200);
         t.parent = this;
         panes.AddWindow(t);
 
         t = CreateInstance<RoomIcon>();
         t.WindowRect = new Rect(300,300,200,100);
         t.parent = this;
         panes.AddWindow(t);
 
         panes.AddWindow(CreateInstance<Black>());
     }
 
     public void Update()
     {
         //panes.OnUpdate();
         if(doRepaint)
             Repaint();
     }
 
     public void OnGUI()
     {
         panes.OnGUI ();
         doRepaint = true;
     }
 }
 
 
 public class RoomIcon : TAGWindow
 {
     public TAGMapEditor parent = null;
 
     public override void OnGUI()
     {
         GUILayout.BeginArea(WindowRect);
         {
             if(Hover)
                 GUI.color = Color.cyan;
             else
                 GUI.color = Color.gray;
             GUI.Box(new Rect(0,0,base.Size.x,base.Size.y),"");
 
             GUILayout.BeginHorizontal("",EditorStyles.toolbarButton);
             {
                 if(GUI.Button(new Rect(0,0,30,20),base.ID.ToString(),EditorStyles.toolbarButton))
                 {
                     EditorWindow.GetWindow<TAGMapEditor>().NewPathStart(base.ID);
                 }
             }
             GUILayout.EndHorizontal();
 
         }
         GUILayout.EndArea();
     }
 }
 
               The issues lay in the extended Window class RoomIcon. When I try to stylize the buttons, I get the error. I've tried separating different parts of code based on EvenType.Repaint and .Layout, but I still run into issues. Any help here would be very much appreciated, as I just don't know, anymore.
Edit: I've tried several different things, and the more I tried, the more I fear I'm gonna need to start over from scratch . . . again. Any assistance in this insanity would be helpful.
Your answer
 
             Follow this Question
Related Questions
Multiple Cars not working 1 Answer
[SOLVED]GUIStyle Word Wrap Check 1 Answer
Can you use GUIStyle with GUILayout? 0 Answers
Distribute terrain in zones 3 Answers
How to set GUIStyle.font 0 Answers