- Home /
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()
Answer by GameNot · Jul 06, 2019 at 10:39 AM
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
Nice workaround. Spent 30 $$anonymous$$ trying to find a fix
Yes, I can confirm this is the case - if you don't have an object selected before pressing play, the error will not appear. It is a known bug in the Unity Editor and will probably be fixed before 2050.
Answer by NikLaws · Mar 10, 2019 at 03:47 PM
A similar question: https://answers.unity.com/questions/1446539/nullreferenceexception-pointing-nowhere.html 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? https://github.com/Unity-Technologies/UnityCsReference/blob/master/Editor/Mono/Inspector/GameObjectInspector.cs
I have already found that and did that. Still getting the error. Also You sent me the link of github, but where can I find that GameObjectInspector file on my project ? so maybe I can chang it? Or I shouldn't?
Answer by dan_wipf · Mar 10, 2019 at 08:53 PM
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
Answer by stakan100gramm · Dec 24, 2020 at 01:50 AM
You just need to send your GameObject to Prefabs.
Answer by reload666 · Mar 22, 2021 at 11:25 AM
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"