NullReferenceException on GameObjectInspector Editor Error

NOTE: NOPE, THIS IS NOT A DUPLICATE OF OTHER NULLREFERENCE EXCEPTION ANSWERS. I KNOW WHAT IS A NULLREFERENCEEXCEPTION AND YES I SEARCHED ALREADY IN THE FORUM AND NONE HAS THIS PROBLEM, SINCE THIS IS AN ERROR FROM UNITY EDITOR.


Hello, why do I get this? I tried to look for GameObjectInspector in th project, I can’t find it !
Where is such PATH? and where this esact script? Nothing found on my hard drive.

 NullReferenceException: Object reference not set to an instance of an object
 UnityEditor.GameObjectInspector.ClearPreviewCache () (at C:/buildslave/unity/build/Editor/Mono/Inspector/GameObjectInspector.cs:201)
 UnityEditor.GameObjectInspector.OnDisable () (at C:/buildslave/unity/build/Editor/Mono/Inspector/GameObjectInspector.cs:189)
 UnityEditor.AssetDatabase:DeleteAsset()
 ES2EditorStartup:Cleanup()
 ES2EditorStartup:.cctor()
 UnityEditor.EditorAssemblies:ProcessInitializeOnLoadAttributes()

Sorry for my bad English! I have the same error, and I find that it happens when I select an object in scene hierarchy and hit play. So as I understand that happens cause unity cant clean inspector. I can’t find the fix for this issue, but if you deselect your selected object in the scene inspector will automatically clear and UnityEditor.GameObjectInspector.ClearPreviewCache () will never be called and this error will not appear

A similar question: NullReferenceException pointing nowhere - Questions & Answers - Unity Discussions
there is a solution proposed that you could try: “Whenever I get errors from Unity’s own library code, I close my project and delete /Temp and /Library. After reopening, the problems are usually gone. It could be worth a shot.”

However, according to GameObjectInspector.cs im guessing you’re missing an asset? Perhaps youre referring to a prefab that doesnt exist?

Mostelikely you reference as @NikLaws says an Object, which does not exist. => NullReference is give en from (go) part of the GameObjectInspector.cs part have a Look below, go is part of a foreach loop

foreach(var go in targets)

btw. you’re not allowed to change GameObjectInspector.cs, it’s readOnly and provided for studies…
and you won’t find it in your Computer, it’s in UnityEditor.dll compiled

//Line 189 (+ 190) from GameObjectInspector.cs
if (!m_IsPrefabInstanceAnyRoot || !PrefabUtility.IsOutermostPrefabInstanceRoot(go))
    m_IsPrefabInstanceOutermostRoot = false; // Conservative is false if any is false
//Line 201 (+200) from GameObjectInspector.cs
if (PrefabUtility.IsPrefabAssetMissing(go))
    m_IsMissing = true;

/* go == foreach(GameObject go in targets) */

Edit

well i did no sime quick research, and mostlikely it the NRE comes from the prefab you use, there’s not realy an answer to it right now, more likely a bug => but the most answers and explenations you probaly get on StackOverflow

You just need to send your GameObject to Prefabs.

sorry my english, knowing that the topic is old, but maybe it helps, I had this problem and it was in the action of my character
when he made an attack and returned to walk or run he presented the error, solution I will adjust the animator, selecting “Has Exit Time”

You can use the following method to delay saving. The workaround is to delay saving the asset until after the inspector has been updated, using EditorApplication.delayCall. For example:

EditorApplication.delayCall += AssetDatabase.SaveAssets;

Thanks, @ConnorFailbetter in another

This worked for me: Closed all Inspector tabs in the editor and then reopen them. The problem disappeared