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?

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?