- Home /
Null Ref Exception in Unity backend?
Hello all,
Today I was creating some objects in the editor when my computer shutdown abruptly. After I rebooted I new get this error when trying to apply changes to the prefab i was working in. The thing is the error references scripts I did not create. They look to be Unity created. I have tried re importing all assets, re downloading my project and reinstalling Unity itself with nothing working. The game still runs fine but not being able to make changes to my main prefab is a killer. If anyone might know how to fix this that would be great. Thanks a lot and see below for the full error.
NullReferenceException: Object reference not set to an instance of an object UnityEditor.PrefabUtility.RegisterNewObjects (System.Collections.Generic.List`1 newHierarchy, System.Collections.Generic.List`1 hierarchy, System.String actionName) (at C:/buildslave/unity/build/Editor/Mono/ImportSettings/PrefabUtility.cs:121) UnityEditor.PrefabUtility.ReplacePrefabWithUndo (UnityEngine.GameObject target) (at C:/buildslave/unity/build/Editor/Mono/ImportSettings/PrefabUtility.cs:223) UnityEditor.GameObjectInspector.DoPrefabButtons (PrefabType prefabType, UnityEngine.GameObject go) (at C:/buildslave/unity/build/Editor/Mono/Inspector/GameObjectInspector.cs:347) UnityEditor.GameObjectInspector.DrawInspector () (at C:/buildslave/unity/build/Editor/Mono/Inspector/GameObjectInspector.cs:260) UnityEditor.GameObjectInspector.OnHeaderGUI () (at C:/buildslave/unity/build/Editor/Mono/Inspector/GameObjectInspector.cs:170) UnityEditor.Editor.DrawHeader () (at C:/buildslave/unity/build/Editor/Mono/Inspector/Editor.cs:420) UnityEditor.InspectorWindow.DrawEditor (UnityEditor.Editor[] editors, Int32 editorIndex, Boolean rebuildOptimizedGUIBlock, System.Boolean& showImportedObjectBarNext, UnityEngine.Rect& importedObjectBarRect) (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1117) UnityEditor.InspectorWindow.DrawEditors (UnityEditor.Editor[] editors) (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:1022) UnityEditor.InspectorWindow.OnGUI () (at C:/buildslave/unity/build/Editor/Mono/Inspector/InspectorWindow.cs:361) 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/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222) Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation. 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/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232) System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115) UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:295) UnityEditor.HostView.Invoke (System.String methodName) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:288) UnityEditor.HostView.InvokeOnGUI (Rect onGUIPosition) (at C:/buildslave/unity/build/Editor/Mono/HostView.cs:255)
Answer by Harinezumi · Feb 05, 2018 at 12:38 PM
I was getting the same error recently after I shut down the computer.
For me the error appeared when I tried to apply changes of a prefab. Fortunately I noticed that a key script says "Nothing selected" instead its name, and that the script cannot be loaded. So I commented out the complete script, let Unity compile, then uncomment it, and now Unity was able to tell me that it can't find a class. For me that class is in a different assembly (I'm using assembly definition files, but instead of helpful, they are a pain in the @$$), but the assembly that was reporting the error did have dependency to it. So I dragged the dependency again, clicked apply, and now everything compiled!
So the issue seems to have been that Unity wasn't able to find a reference to an assembly, and instead of reporting that it cannot build a script, it had issues with displaying it.
Maybe in your case you also have a script that cannot compile...
Good spot. Same problem caused by deleting a component but not the usage reference in the prefab. Really should have a proper error report to handle this simple case!
I'm glad it was useful! :) And indeed, they should report the error properly, but it is still very-very beta, so I guess that's why it doesn't. I wish Unity Tech didn't use devs as their guinea pigs for half-baked new features :(
Answer by AtifatGamy · Jan 18, 2019 at 11:08 AM
This problem is due to a "Missing Reference Script" in your prefab. Somewhere in its hierarchy, you have a Missing Script or a Missing Prefab (in your drag&drops elements, probably).
I've deleted the components with "Missing Reference Script" and set to "None" drag&drop elements in my inspector, reapply, and it worked !
Answer by MikeDockery · May 10, 2019 at 02:31 PM
i had removed the animator component from the model in the inspector, this seemed to cause the error as when i reverted back to having it, the error stoped.
Your answer

Follow this Question
Related Questions
Can no longer create pre-fab 1 Answer
very weird NullReferenceException error causeing one script to break another 2 Answers
Object reference to set to instance on an instantiated object 1 Answer
Variable Assigning with GameObject.Find("") causing NullReferenceException? 0 Answers
how to CORRECTLY load all assets (using Resources.LoadAll) 1 Answer