AnimationEvent.animationState help: NullReferenceException

Okay so I added this event to the timeline of my animation at a certain frame. I want to know what animation state had sent this event. Except I get this error:

ThisCScript.someSuch (UnityEngine.AnimationEvent ae) (at Assets/Dude/ThisCScript.cs:94)

Here’s the function that is being called by the event.

public void someSuch (AnimationEvent ae)
		AnimationState state = ae.animationState;
		string name =;
		print (name);
		print (ae.floatParameter);
		print (ae.intParameter);
		print (ae.stringParameter);

If I comment out the string name = part, and also the print(name) parts, the code works fine. It outputs the parameters just fine.

I even tried to use the debugger. When I looked at the value for ae.animationState, it said “object reference not set to an instance of an object”. I am not sure what causes this though. I mean the script is most certainly called by an animation. Can anybody tell me what I’m doing wrong?

If you are using the Animator component, and not the legacy Animation component, you should use animatorStateInfo property of the AnimationEvent instead of animationState. animatorStateInfo will not be null when the function is called from an Animator’s animation event.

More information about AnimatorStateInfo can be found here: