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. Dismiss Notice

Unity Editor - To-Do-List, 'Getting Control 3's position'

Discussion in 'Scripting' started by TaleOf4Gamers, Jul 1, 2016.

  1. TaleOf4Gamers

    TaleOf4Gamers

    Joined:
    Nov 15, 2013
    Posts:
    825
    Hey all,
    I am here with an issue concerning a To-Do-List that I started using.
    Before I start, this issue doe not break it merely spams the console so I would love to fix it.

    The custom editor window for the To-Do-List starts spamming the console when you drag it.
    Code (CSharp):
    1. ArgumentException: Getting control 3's position in a group with only 3 controls when doing mouseDrag
    2. Aborting
    I have heard that it is to do with the OnGUI and Repaint().
    Because of this I will post the OnGUI here.
    If you need anything else just let me know although the full script is 600 lines long.
    The Code:
    Code (CSharp):
    1.         void OnGUI()
    2.         {
    3.             if (list != null)
    4.             {
    5.                 if (EditorGUILayout.BeginFadeGroup(showGroups.faded))
    6.                 {
    7.                     ShowToDoList();
    8.                 }
    9.                 EditorGUILayout.EndFadeGroup();
    10.  
    11.                 if (EditorGUILayout.BeginFadeGroup(showEditingGroups.faded))
    12.                 {
    13.                     ShowGroupEditing();
    14.                 }
    15.                 EditorGUILayout.EndFadeGroup();
    16.  
    17.                 if (EditorGUILayout.BeginFadeGroup(showPreferences.faded))
    18.                 {
    19.                     ShowPreferences();
    20.                 }
    21.                 EditorGUILayout.EndFadeGroup();
    22.             }
    23.             else
    24.             {
    25.                 GUIStyle warningLabel = new GUIStyle(GUI.skin.label);
    26.                 warningLabel.alignment = TextAnchor.MiddleCenter;
    27.  
    28.                 GUI.Label(new Rect(0, 0, size.x, size.y), "The To-Do List can't be found in 'Resources/Editor'.\nPressing 'Fix Now' will create a Resources folder in the 'Assets' folder.", warningLabel);
    29.  
    30.                 if (GUI.Button(new Rect(size.x / 2 - 100, size.y / 2 + 20, 200, 20), "Fix Now"))
    31.                 {
    32.                     if (!Directory.Exists(Application.dataPath + "/Resources/Editor"))
    33.                     {
    34.                         Directory.CreateDirectory(Application.dataPath + "/Resources/Editor");
    35.                     }
    36.  
    37.                     ToDoListObject asset = CreateInstance<ToDoListObject>();
    38.                     Group bugsGroup = new Group();
    39.                     Group featuresGroup = new Group();
    40.                     PriorityGroup criticalGroup = new PriorityGroup();
    41.                     PriorityGroup majorGroup = new PriorityGroup();
    42.                     PriorityGroup minorGroup = new PriorityGroup();
    43.                  
    44.  
    45.                     criticalGroup.groupColor = new Color(1f, 0f, 0f);
    46.                     criticalGroup.groupName = "Critical";
    47.                     criticalGroup.labelStyle = FontStyle.Bold;
    48.                     majorGroup.groupColor = new Color(0f, 0f, 1f);
    49.                     majorGroup.groupName = "Major";
    50.                     minorGroup.groupColor = new Color(1f, 0f, 1f);
    51.                     minorGroup.groupName = "Minor";
    52.                     bugsGroup.groupColor = new Color(1f, 0.5f, 0f);
    53.                     bugsGroup.groupName = "Bugs";
    54.                     featuresGroup.groupColor = new Color(0f, 0.5f, 0f);
    55.                     featuresGroup.groupName = "Features";
    56.  
    57.                     asset.groups.Add(bugsGroup);
    58.                     asset.groups.Add(featuresGroup);
    59.                     asset.priorityGroups.Add(criticalGroup);
    60.                     asset.priorityGroups.Add(majorGroup);
    61.                     asset.priorityGroups.Add(minorGroup);
    62.  
    63.                     string path = AssetDatabase.GenerateUniqueAssetPath("Assets/Resources/Editor/ToDoList.asset");
    64.                     AssetDatabase.CreateAsset(asset, path);
    65.                     AssetDatabase.SaveAssets();
    66.                     AssetDatabase.Refresh();
    67.                     UpdateAnimBools();
    68.                     MakeGroupEditingList();
    69.                     MakePrioritiesEditingList();
    70.                 }
    71.             }
    72.  
    73.             if(Event.current.type == EventType.ValidateCommand)
    74.             {
    75.                 if(Event.current.commandName == "UndoRedoPerformed")
    76.                 {
    77.                     Repaint();
    78.                 }
    79.             }
    80.  
    81.             EditorUtility.SetDirty(list);
    82.         }
    Any help would be greatly appreciated as I am trying to teach a buddy about Unity and if he sees this then it will confuse him a little. (He is a 3D Modeller)
     
  2. TaleOf4Gamers

    TaleOf4Gamers

    Joined:
    Nov 15, 2013
    Posts:
    825
  3. jimroberts

    jimroberts

    Joined:
    Sep 4, 2014
    Posts:
    560
    Code (CSharp):
    1. if (list!= null) <-- //This is most likely the problem.
    OnGUI is called multiple times every frame. If the reference to "list" changes between OnGUI calls it will throw the exception because the number of controls to render will change..
     
  4. TaleOf4Gamers

    TaleOf4Gamers

    Joined:
    Nov 15, 2013
    Posts:
    825
    Interesting, I don't really know how to approach this as it is a first for me. I obviously cant just remove the if statement as it will mess with the window as I just attempted.
     
  5. TaleOf4Gamers

    TaleOf4Gamers

    Joined:
    Nov 15, 2013
    Posts:
    825
    I have sifted through quite a few of threads similar to these that simply have no replies.
     
  6. jimroberts

    jimroberts

    Joined:
    Sep 4, 2014
    Posts:
    560
    Is your "list" reference being changed in OnGUI or any of the methods that are called in OnGUI? I assume it is because of your call to "ShowToDoList();".. I would need more code related to "list" in order to help you fix it.
     
  7. TaleOf4Gamers

    TaleOf4Gamers

    Joined:
    Nov 15, 2013
    Posts:
    825
    It does not appear so.
    However there is this:
    Code (CSharp):
    1. EditorUtility.SetDirty(list);
    It is certainly not the first time that I have seen this so I decided to look at the Docs for it. Apparently it is looking to being deprecated soon in later version. Considering that I have using Unity 5.4 Beta so I dont know if that matters.

    EDIT:
    This editor tool does not change anything in the scene so this message is most likely useless. Just better to make sure.
     
  8. jimroberts

    jimroberts

    Joined:
    Sep 4, 2014
    Posts:
    560
    What happens when you remove lines 73 to 81. Does the exception still get thrown?
     
  9. TaleOf4Gamers

    TaleOf4Gamers

    Joined:
    Nov 15, 2013
    Posts:
    825
    Unfortunately yes. I will continue to look.
     
  10. TaleOf4Gamers

    TaleOf4Gamers

    Joined:
    Nov 15, 2013
    Posts:
    825
    Bumperino, any ideas on how to fix it? (I understand the if may be the issue but I don't know to remedy it)
     
  11. jimroberts

    jimroberts

    Joined:
    Sep 4, 2014
    Posts:
    560
    You don't have enough code posted for me to be able to make a solid judgment on the issue. The only thing that stands out is the "list" reference possibly changing.. Post the code for all the functions that are being called within OnGUI.