0
Postponed

NullReferenceException when peeking prefab in project window

aspirit.128 7 months ago updated by Lazlo Bonin (Lead Developer) 6 months ago 1

When clicking on prefab icon in project window (to peek it later) an exception occurs:

NullReferenceException: Object reference not set to an instance of an object
UnityEditor.PrefabImporterEditor.Awake () (at <480b5a3bd3214ce5831f6dd8c68fdc55>:0)
UnityEditor.Editor:CreateEditor(Object)
Ludiq.Peek.EditorPopup:Initialize(Object[]) (at Assets/Plugins/Ludiq/Ludiq.Peek/Editor/Tools/Editor/EditorPopup.cs:129)
Ludiq.Peek.EditorPopup:Open(Object[], Rect) (at Assets/Plugins/Ludiq/Ludiq.Peek/Editor/Tools/Editor/EditorPopup.cs:55)
Ludiq.Peek.EditorTool`1:Open(ToolControl) (at Assets/Plugins/Ludiq/Ludiq.Peek/Editor/Tools/Editor/EditorTool.cs:123)
Ludiq.Peek.GameObjectEditorTool:Open(ToolControl) (at Assets/Plugins/Ludiq/Ludiq.Peek/Editor/Tools/Editor/Implementation/GameObjectEditorTool.cs:68)
Ludiq.Peek.ToolControl:DrawInTreeView(Boolean, Rect, Boolean) (at Assets/Plugins/Ludiq/Ludiq.Peek/Editor/Tools/ToolControl.cs:233)
Ludiq.Peek.ToolbarControl:DrawMainToolInTreeView(Rect, Rect) (at Assets/Plugins/Ludiq/Ludiq.Peek/Editor/Toolbars/ToolbarControl.cs:149)
Ludiq.Peek.TreeViewToolbars:Draw(Boolean, ToolbarControlProvider, Object, Object[], Boolean, String, Rect, Rect, Boolean) (at Assets/Plugins/Ludiq/Ludiq.Peek/Editor/Toolbars/Integrations/TreeViewToolbars.cs:55)
Ludiq.Peek.TreeViewToolbars:OnItemGUI(ToolbarControlProvider, Object, Rect, Rect, Boolean) (at Assets/Plugins/Ludiq/Ludiq.Peek/Editor/Toolbars/Integrations/TreeViewToolbars.cs:125)
Ludiq.Peek.ProjectToolbars:OnProjectItemGUI(String, Rect) (at Assets/Plugins/Ludiq/Ludiq.Peek/Editor/Toolbars/Integrations/ProjectToolbars.cs:65)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

Unity Version:
2019.3.13f1
Peek Version:
1.1.8
GOOD, I'M SATISFIED

thanks for investigating this issue

Satisfaction mark by aspirit.128 6 months ago
Postponed

Hi Aspirit.128,

Sorry for the issue and the delay in my answer, and thank you for the bug report.

Long story short, this is a Unity issue and I cannot find a way to either fix it, or even to prevent the error from showing in the console. It doesn't seem to cause any serious issue though, although it might lead to some unexpected behaviour if your prefab has missing scripts.

I will mark this as postponed for now and try to get someone at Unity to have modify their API to let us fix it properly.

I've investigated and found out that this is caused by the fact that we initialize our PrefabImporterEditor after its Awake frame using InternalSetAssetImporterTargetEditor. Unfortunately, the importer editors rely on this method being called before Awake, which is done via the internal native side of the engine and not something we can do as a third-party extension. Unfortunately, I can't even prevent the error from showing up, because wrapping our call in a try/catch block doesn't work, because the error is not actually thrown but handled and logged at a lower level.