WooshiiDev / HierarchyDecorator

Lightweight Unity Plugin transforming the Hierarchy into what it should be. Adds headers, styles, icons and more.
MIT License
1.02k stars 47 forks source link

Errors on import of HierarchyDecorator.unitypackage in new project #2

Closed MostHated closed 4 years ago

MostHated commented 4 years ago

----- Edit - Nevermind, lol. After all that I did in the second post, I went to look at the code in the repo and saw you already fixed this and I just had not updated on my end to have the changes. >_<

Hey there again, I was just using the demo from this repo before and just now tried to add the .unitypackage that was included with it into a new project but was unfortunately greeted with errors right away, so I just wanted to make sure you were aware of them.

This was a new project - Unity 2020.1.4f1 with the standard renderer. None of the errors occur in the demo project, I also just tried it with a new 2019.4.9f1 project and there were no errors there. Though, all new projects I have been starting/using use 2020.1.x

With only importing and doing nothing else, the modifications to the hierarchy were applied:

But these two showed up:

Index was out of range ``` ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index System.ThrowHelper.ThrowArgumentOutOfRangeException (System.ExceptionArgument argument, System.ExceptionResource resource) (at :0) System.ThrowHelper.ThrowArgumentOutOfRangeException () (at :0) HierarchyDecorator.HierarchyDecoratorSettings.UpdateSettings () (at Assets/HierarchyDecorator/Editor/Settings/HierarchyDecoratorSettings.cs:249) HierarchyDecorator.HierarchyDecorator.GetSettings () (at Assets/HierarchyDecorator/Editor/HierarchyDecorator.cs:339) HierarchyDecorator.HierarchyDecorator.HandleObject (System.Int32 instanceID, UnityEngine.Rect selectionRect) (at Assets/HierarchyDecorator/Editor/HierarchyDecorator.cs:51) UnityEditor.SceneHierarchy.OnRowGUICallback (System.Int32 instanceID, UnityEngine.Rect rect) (at <3b1af5075b0340cfb428dfcef292b2ea>:0) UnityEditor.IMGUI.Controls.TreeViewController.DoItemGUI (UnityEditor.IMGUI.Controls.TreeViewItem item, System.Int32 row, System.Single rowWidth, System.Boolean hasFocus) (at <3b1af5075b0340cfb428dfcef292b2ea>:0) UnityEditor.IMGUI.Controls.TreeViewController.IterateVisibleItems (System.Int32 firstRow, System.Int32 numVisibleRows, System.Single rowWidth, System.Boolean hasFocus) (at <3b1af5075b0340cfb428dfcef292b2ea>:0) UnityEditor.IMGUI.Controls.TreeViewController.OnGUI (UnityEngine.Rect rect, System.Int32 keyboardControlID) (at <3b1af5075b0340cfb428dfcef292b2ea>:0) UnityEditor.SceneHierarchy.DoTreeView (System.Single searchPathHeight) (at <3b1af5075b0340cfb428dfcef292b2ea>:0) UnityEditor.SceneHierarchy.OnGUI (UnityEngine.Rect rect) (at <3b1af5075b0340cfb428dfcef292b2ea>:0) UnityEditor.SceneHierarchyWindow.DoSceneHierarchy () (at <3b1af5075b0340cfb428dfcef292b2ea>:0) UnityEditor.SceneHierarchyWindow.OnGUI () (at <3b1af5075b0340cfb428dfcef292b2ea>:0) UnityEditor.HostView.InvokeOnGUI (UnityEngine.Rect onGUIPosition, UnityEngine.Rect viewRect) (at <3b1af5075b0340cfb428dfcef292b2ea>:0) UnityEditor.DockArea.DrawView (UnityEngine.Rect viewRect, UnityEngine.Rect dockAreaRect) (at <3b1af5075b0340cfb428dfcef292b2ea>:0) UnityEditor.DockArea.OldOnGUI () (at <3b1af5075b0340cfb428dfcef292b2ea>:0) UnityEngine.UIElements.IMGUIContainer.DoOnGUI (UnityEngine.Event evt, UnityEngine.Matrix4x4 parentTransform, UnityEngine.Rect clippingRect, System.Boolean isComputingLayout, UnityEngine.Rect layoutSize, System.Action onGUIHandler, System.Boolean canAffectFocus) (at :0) UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&) ```
pushing more GUIClips than you are popping ``` GUI Error: You are pushing more GUIClips than you are popping. Make sure they are balanced. UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&) ```

I then went to click on the settings SO and the console exploded:

Index was out of range ``` ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index System.ThrowHelper.ThrowArgumentOutOfRangeException (System.ExceptionArgument argument, System.ExceptionResource resource) (at :0) System.ThrowHelper.ThrowArgumentOutOfRangeException () (at :0) HierarchyDecorator.HierarchyDecoratorSettings.UpdateSettings () (at Assets/HierarchyDecorator/Editor/Settings/HierarchyDecoratorSettings.cs:249) HierarchyDecorator.HierarchyDecoratorSettings.OnBeforeSerialize () (at Assets/HierarchyDecorator/Editor/Settings/HierarchyDecoratorSettings.cs:209) UnityEditor.SerializedObject:UpdateIfRequiredOrScript() HierarchyDecorator.HierarchyDecoratorSettingsEditor:OnInspectorGUI() (at Assets/HierarchyDecorator/Editor/Settings/HierarchyDecoratorSettingsEditor.cs:74) UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&) ```

MostHated commented 4 years ago

Looking a bit more into this:

It looks like there is a possibility that the Component Types:

// --- Starting line 79 in HierarchyDecoratorSettings.cs
/// <summary>
/// List of all components
/// Required for easier handling of serialization
/// </summary>
public List<ComponentType> components;

that were stored in the ScriptableObject that was saved as HierarchyDecorator.unitypackage using Unity 2019.x differs from the available Types in 2020.1,

If you see below this was just one quick one that I saw when looking at the ScriptableObject's data that came directly out of the HierarchyDecorator.unitypackage vs a new one I create myself.

(Upon creating the Settings.asset manually, it was lacking a bunch of default settings, but also, the init processes and HierarchyDecoratorSettings.GetOrCreateSettings() didn't seem to work properly, but I didn't dig much into that.)

In here, after trying to do some checking, it seemed like the main issue was the components list, as you see in my comment below.

 public void UpdateSettings()
            {
            if (allTypes == null)
                allTypes = ReflectionUtility.GetTypesFromAllAssemblies (typeof (Component));

            if (components == null) // Not null, but also the stored components.Count != allTypes.Length above.
                {
                components = new List<ComponentType> ();

                for (int i = 0; i < allTypes.Length; i++)
                    {
                    var type = allTypes[i];
                    components.Add (new ComponentType (type));
                    }
                }

            for (int i = 0; i < allTypes.Length; i++)
                {
                var type = allTypes[i];

                if (components[i].type == null)
                    components[i].UpdateType (type);

                if (!shownComponents.ContainsKey (name))
                    shownComponents.Add (name, components[i]);
                }
            }
        }

I was able to get it working properly just just tossing in: components = null; just before the null check so that it would recreate it. Also though, probably checking something like the below might help prevent it:

(components is null || components.Count != allTypes.Length)

The UpdateSettings() also seemed to get called what looked like every UI frame due to the following

HierarchyDecorator()
...
EditorApplication.hierarchyWindowItemOnGUI -= HandleObject;
EditorApplication.hierarchyWindowItemOnGUI += HandleObject; // <--

Then worked my way down a bit.

HandleObject()
...
GetSettings(); // <--
GetSettings();
...
settings.UpdateSettings(); // <--

Not sure if that is intended and probably only really seems a bit excessive because it was having errors.

WooshiiDev commented 4 years ago

Hey there, sorry for the late reply, I'm doing this on the side of my other work so sometimes I may be a day or so behind šŸ˜ž

Yeah I realised the issue of your first error quite quickly, unfortunately some null checks have been ignorantly avoided, but I need to go through a massive refactor when it comes to the HierarchyDecorator.cs file. That'll most likely be this weekend.

For the component-type checks with versioning, I realised that too, and that'll be one of the next priorities, as I updated the directives for 2020.1 and higher and some differences were noticed when I tested in 2020.

I would also say that the UpdateSettings//GetSettings error should have a null check prior and thus will only call once, unless that's due to said errors above.

I'll keep this open until you read these as I closed the previous one without any response chance (sorry about that, wasn't thinking right)

I appreciate the comments by the way! I'll totally keep up to date with anything else you put here, thank you again! ~ Wooshii

MostHated commented 4 years ago

No worries. I wish I had seen you pushed fixes already for things before I spent the time going through them. I didn't realize until after I wrote that up, lol. Everything else seemed to be working well so far though. šŸ‘