Destroying GameObject while in Inspector = MissingReferenceException
I have a behaviour that just acts as a data container that's on one of my models.
If I select that game object so that the script is displayed in the behaviour, and tweak the model import settings and click "Apply" I get an error (thrown repeatedly until I make the inspector focus on another object).
MissingReferenceException: The object of type 'MyComponent' has been destroyed but you are still trying to access it.
Your script should either check if it is null or you should not destroy the object.
UnityEditor.Editor.IsEnabled () (at C:/buildslave/unity/build/Editor/Mono/Inspector/Editor.cs:589)
UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor editor, Int32 editorIndex, Boolean rebuildOptimizedGUIBlock, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect) (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1151)
UnityEditor.InspectorWindow.DrawEditors (UnityEditor.Editor[] editors) (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1028)
UnityEditor.InspectorWindow.OnGUI () (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:352)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
Now, my asset processor is updating a prefab, copying that component, and then calling DestroyImmediate, which I'm sure is why the error is being generated.
However, I can find no way to protect against this.
Perhaps some way to just clear the selected object so that the inspector isn't on it?
Your answer
Follow this Question
Related Questions
MissingReferenceException when locking inspector tab 0 Answers
Unity error The object of type 'Preview' has been destroyed but you are still trying to access it. 0 Answers
Weird MissingReferenceException 0 Answers
Why i can't see scenes in inspector? 0 Answers
How do I use EditorGUILayout.EnumPopup with an enum with 'holes' in a custom inspector. 3 Answers