How do you get a value from the Animator?

It seems simple enough, but my ‘mAnimator.GetFloat(“Acceleration”)’ call always returns 0. However, in the Animator window I can see there is a value.

Here’s a quick snipped of code:

mAnimator.SetFloat("Acceleration", mAcceleration); //, 0.04f, Time.deltaTime);

// Debug the state changes
if (mLastState != mStateInfo.nameHash)
{
	int lAccelerationID = Animator.StringToHash("Acceleration");
	float lAcceleration = mAnimator.GetFloat(lAccelerationID);

	Debug.Log("[" + Time.time + "] Animator state change: " + mStateLookup[mLastState] + " -> " + mStateLookup[mStateInfo.nameHash] + " Acc:" + lAcceleration);
	mLastState = mStateInfo.nameHash;
}

Animations are running correctly and I can see the Acceleration value changing in the editor. I’m just surprised I can’t get it in code.

Is there a trick to this?

Thanks!

So you’ve tried both overloads of GetFloat? i.e.

int lAccelerationID = Animator.StringToHash("Acceleration");
float lAcceleration = mAnimator.GetFloat(lAccelerationID);

and:

float lAcceleration = mAnimator.GetFloat("Acceleration");

and neither works? Can you post a screenshot of your Animator window?

Hi Tanoshimi,

When trying to get a screenshot, it started working. I had closed the project and reopened it so maybe that helped(?)

I guess I’ll call this closed.

Thanks for responding.