Question by
SaganTucker · Sep 25, 2015 at 04:45 PM ·
animatorgetcomponentnull reference exception
Null Reference Exception for Animator
Hi guys, I started getting a null reference exception when I try to do the following...
private Animator anim;
anim = GetComponent<Animator> ();
anim.SetFloat ("speed", h); //throws null reference exception error
It was working fine earlier. Both the script and the Animator are on the same game object.
Any idea what's going on?
Comment
Answer by Zymurer · Apr 02, 2019 at 09:49 PM
Maybe you are trying to find/access a parameter that doesn't exist.
For example, that unity gave us. They have an animator tab like this:
And in the code they tried to access "horizontalSpeed" varible.
m_Animator.SetFloat("horizontalSpeed", m_HorizontalMovement);
Do you have "speed" parameter on your animator?
animatorsetfloat.png
(319.4 kB)