Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

NullReferenceException when right clicking in the Hierarchy window #33

Open
Edvinas01 opened this issue Sep 29, 2022 · 1 comment
Open

Comments

@Edvinas01
Copy link

Versions

  • Unity: 2020.3.20f1.
  • Smart Hierarchy: 0.3.1.

Repro steps

  • Create new scene.
  • Open the scene.
  • Right click in the Hierarchy window.
  • Context menu doesn't open and an exception is thrown.

Exception

NullReferenceException: Object reference not set to an instance of an object
AV.Hierarchy.GenericMenuUtil.GetItems (UnityEditor.GenericMenu menu) (at Library/PackageCache/[email protected]/Reflected/GenericMenuUtil.cs:21)
AV.Hierarchy.CopyPasteCommands.<OnInitialize>g__ReplaceMenuFunctions|6_2 (UnityEditor.GenericMenu menu) (at Library/PackageCache/[email protected]/Base/Commands/CopyPasteCommands.cs:28)
AV.Hierarchy.CopyPasteCommands+<>c.<OnInitialize>b__6_0 (UnityEditor.GenericMenu menu, UnityEngine.GameObject o) (at Library/PackageCache/[email protected]/Base/Commands/CopyPasteCommands.cs:21)
UnityEditor.SceneManagement.SceneHierarchyHooks.AddCustomGameObjectContextMenuItems (UnityEditor.GenericMenu menu, UnityEngine.GameObject gameObject) (at <83a38f5397d94e36a22efa3369c82390>:0)
UnityEditor.SceneHierarchy.CreateGameObjectContextClick (UnityEditor.GenericMenu menu, System.Int32 contextClickedItemID) (at <83a38f5397d94e36a22efa3369c82390>:0)
UnityEditor.SceneHierarchy.ContextClickOutsideItems () (at <83a38f5397d94e36a22efa3369c82390>:0)
UnityEditor.IMGUI.Controls.TreeViewController.HandleUnusedEvents () (at <83a38f5397d94e36a22efa3369c82390>:0)
UnityEditor.IMGUI.Controls.TreeViewController.OnGUI (UnityEngine.Rect rect, System.Int32 keyboardControlID) (at <83a38f5397d94e36a22efa3369c82390>:0)
UnityEditor.SceneHierarchy.DoTreeView (System.Single searchPathHeight) (at <83a38f5397d94e36a22efa3369c82390>:0)
UnityEditor.SceneHierarchy.OnGUI (UnityEngine.Rect rect) (at <83a38f5397d94e36a22efa3369c82390>:0)
UnityEditor.SceneHierarchyWindow.DoSceneHierarchy () (at <83a38f5397d94e36a22efa3369c82390>:0)
UnityEditor.SceneHierarchyWindow.OnGUI () (at <83a38f5397d94e36a22efa3369c82390>:0)
UnityEditor.HostView.InvokeOnGUI (UnityEngine.Rect onGUIPosition, UnityEngine.Rect viewRect) (at <83a38f5397d94e36a22efa3369c82390>:0)
UnityEditor.DockArea.DrawView (UnityEngine.Rect viewRect, UnityEngine.Rect dockAreaRect) (at <83a38f5397d94e36a22efa3369c82390>:0)
UnityEditor.DockArea.OldOnGUI () (at <83a38f5397d94e36a22efa3369c82390>: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 <4c8a9874288b4fb78fa7fdbcd8065b00>:0)
UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, UnityEngine.Matrix4x4 worldTransform, UnityEngine.Rect clippingRect, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <4c8a9874288b4fb78fa7fdbcd8065b00>:0)
UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, System.Action onGUIHandler, System.Boolean canAffectFocus) (at <4c8a9874288b4fb78fa7fdbcd8065b00>:0)
UnityEngine.UIElements.IMGUIContainer.HandleIMGUIEvent (UnityEngine.Event e, System.Boolean canAffectFocus) (at <4c8a9874288b4fb78fa7fdbcd8065b00>:0)
UnityEngine.UIElements.IMGUIContainer.SendEventToIMGUIRaw (UnityEngine.UIElements.EventBase evt, System.Boolean canAffectFocus, System.Boolean verifyBounds) (at <4c8a9874288b4fb78fa7fdbcd8065b00>:0)
UnityEngine.UIElements.IMGUIContainer.SendEventToIMGUI (UnityEngine.UIElements.EventBase evt, System.Boolean canAffectFocus, System.Boolean verifyBounds) (at <4c8a9874288b4fb78fa7fdbcd8065b00>:0)
UnityEngine.UIElements.IMGUIContainer.HandleEvent (UnityEngine.UIElements.EventBase evt) (at <4c8a9874288b4fb78fa7fdbcd8065b00>:0)
UnityEngine.UIElements.EventDispatchUtilities.PropagateEvent (UnityEngine.UIElements.EventBase evt) (at <4c8a9874288b4fb78fa7fdbcd8065b00>:0)
UnityEngine.UIElements.MouseEventDispatchingStrategy.SendEventToRegularTarget (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.BaseVisualElementPanel panel) (at <4c8a9874288b4fb78fa7fdbcd8065b00>:0)
UnityEngine.UIElements.MouseEventDispatchingStrategy.SendEventToTarget (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.BaseVisualElementPanel panel) (at <4c8a9874288b4fb78fa7fdbcd8065b00>:0)
UnityEngine.UIElements.MouseEventDispatchingStrategy.DispatchEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel iPanel) (at <4c8a9874288b4fb78fa7fdbcd8065b00>:0)
UnityEngine.UIElements.EventDispatcher.ApplyDispatchingStrategies (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel, System.Boolean imguiEventIsInitiallyUsed) (at <4c8a9874288b4fb78fa7fdbcd8065b00>:0)
UnityEngine.UIElements.EventDispatcher.ProcessEvent (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel) (at <4c8a9874288b4fb78fa7fdbcd8065b00>:0)
UnityEngine.UIElements.EventDispatcher.Dispatch (UnityEngine.UIElements.EventBase evt, UnityEngine.UIElements.IPanel panel, UnityEngine.UIElements.DispatchMode dispatchMode) (at <4c8a9874288b4fb78fa7fdbcd8065b00>:0)
UnityEngine.UIElements.BaseVisualElementPanel.SendEvent (UnityEngine.UIElements.EventBase e, UnityEngine.UIElements.DispatchMode dispatchMode) (at <4c8a9874288b4fb78fa7fdbcd8065b00>:0)
UnityEngine.UIElements.UIElementsUtility.DoDispatch (UnityEngine.UIElements.BaseVisualElementPanel panel) (at <4c8a9874288b4fb78fa7fdbcd8065b00>:0)
UnityEngine.UIElements.UIElementsUtility.UnityEngine.UIElements.IUIElementsUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr, System.Boolean& eventHandled) (at <4c8a9874288b4fb78fa7fdbcd8065b00>:0)
UnityEngine.UIElements.UIEventRegistration.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr) (at <4c8a9874288b4fb78fa7fdbcd8065b00>:0)
UnityEngine.UIElements.UIEventRegistration+<>c.<.cctor>b__1_2 (System.Int32 i, System.IntPtr ptr) (at <4c8a9874288b4fb78fa7fdbcd8065b00>:0)
UnityEngine.GUIUtility.ProcessEvent (System.Int32 instanceID, System.IntPtr nativeEventPtr, System.Boolean& result) (at <00a477ed1abf4030be646c3244bd3667>:0)
@alexanderameye
Copy link

Something like this should work

  #if UNITY_2021_2_OR_NEWER
        static PropertyInfo menuItemsField = typeof(GenericMenu).GetProperty("menuItems",
            BindingFlags.NonPublic |
            BindingFlags.Instance);
        #else
        static FieldInfo menuItemsField = typeof(GenericMenu).GetField("menuItems",
            BindingFlags.NonPublic |
            BindingFlags.Instance);
        #endif

in the GenericMenuUtil.cs script. I hope a fix for this can be added.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants