Spammed with a Null Reference exception in Animator

I don’t know how to track down what asset is missing… this is an editor error, not an in-game issue.

Works fine in-game.

However, my game started taking 20-50 seconds to load after this error began:

NullReferenceException: Object reference not set to an instance of an object
UnityEditor.Graphs.AnimationStateMachine.TransitionEditionContext.BuildNames () (at C:/buildslave/unity/build/Editor/Graphs/UnityEditor.Graphs/AnimationStateMachine/TransitionEditionContext.cs:44)
UnityEditor.Graphs.AnimationStateMachine.TransitionEditionContext..ctor (UnityEditor.Animations.AnimatorTransitionBase aTransition, UnityEditor.Animations.AnimatorState aSourceState, UnityEditor.Animations.AnimatorStateMachine aSourceStateMachine, UnityEditor.Animations.AnimatorStateMachine aOwnerStateMachine) (at C:/buildslave/unity/build/Editor/Graphs/UnityEditor.Graphs/AnimationStateMachine/TransitionEditionContext.cs:28)
UnityEditor.Graphs.AnimationStateMachine.AnimatorTransitionInspectorBase.ComputeTransitionContexts () (at C:/buildslave/unity/build/Editor/Graphs/UnityEditor.Graphs/AnimationStateMachine/AnimatorTransitionInspectorBase.cs:125)
UnityEditor.Graphs.AnimationStateMachine.AnimatorTransitionInspectorBase.OnEnable () (at C:/buildslave/unity/build/Editor/Graphs/UnityEditor.Graphs/AnimationStateMachine/AnimatorTransitionInspectorBase.cs:87)
UnityEditor.Graphs.AnimationStateMachine.AnimatorStateTransitionInspector.OnEnable () (at C:/buildslave/unity/build/Editor/Graphs/UnityEditor.Graphs/AnimationStateMachine/AnimatorStateTransitionInspector.cs:55)
1 Like

it also happened to me when I was adding extra animation states and then I removed them, just followed Wildan suggestion to close Unity and reopen it again and that fixed it for me

It’s a bug. Restart Editor

Actually I noticed that when changing my “has exit time” checkbox in an animation state, my FindGameObjectWithTag(“Player”) script references will no longer work. You have to restart it to recompile everything correctly. An interesting situation since everything works fine otherwise. I just wonder if you were altering animation states when this happened.

I got same error . But i fixed that deleting all meta files in assets folder/subfolder inside. If unity running close unity and after delete (meta files). Its must work .

This is caused by having an animation state of length 0 somewhere. The unity code divides by animation length in lots of places, assuming that this value will always be > 0.

This causes various bugs throughout the editor (like difference in effective lengths classic).

A restart will temporarily fix this particular bug, or making sure all animations / states have an exit time > 0 set will resolve it permanently. At least until the Unity devs decide to go through the code and put if (!= 0) before each instance of / length.

just close the Animator window and open it up again

This has happened to me before out of nowhere – I don’t know when exactly it started with the project. Closing and reopening the project fixed it automatically.

For me the bug rises each time I had the GameObject selected in the editor’s scene. When I select anything else or nothing the error doesn’t appear anymore…

I thought I was doomed (Unity version 2022.3.16f1) but in fact, just closing (terminating!) the Animator tab and opening it again with Window → Animation → Animator fixed the problem. I think this all went wrong when I renamed an animation. Why does Animator break under so many trivial circumstances? That’s the real question.

NullReferenceException means the object referenced doesn’t exist. It’s not exclusive to scripting. If you deleted the actual animation file from your object you’ll have to reload the object.

or

in my case I copied a gameobject whose have a animator Controller,
for solving I just again assigned a controller in animator(inspector), thats resolve my error.
hope this will help you