How can I access the AnimationState component?

Hey everyone,

I’m having a Sprite with an Animator component and when I’m trying to access the AnimationState I’m getting this error:

ArgumentException: GetComponent requires that the requested component ‘AnimationState’ derives from MonoBehaviour or Component or is an interface.

This is the relevant code part:

Transform test = BIG_parent.transform.FindChild("big2D").gameObject.transform.FindChild("big_idle_0");
        anim2dState = test.GetComponent<Animator>().GetComponent<AnimationState>();

I also tried test.gameObject.GetComponent<Animator>().gameObject.GetComponent<AnimationState>(); or test.gameObject.GetComponent<AnimationState>();
or various combinations of these variants.

The class that contains this code inherits MonoBehaviour.
AnimationState apparently inherits from TrackedReference, which is depricated and has no documentation.

I can’t use the Animation component instead of the animator, because I need to be able to set the Speed parameter of the Animator to -1, and I need the AnimationState to access the AnimationState.length and AnimationState.time

I can post more code or information if you need it.
Thanks for your time.

Ok, I think I found a work around. Animator has the GetCurrentAnimatorStateInfo() method, and it looks as if this method can give me all the information I need. At least I’m not getting error messages anymore.

Animator test = BIG_parent.transform.FindChild("big2D").gameObject.transform.FindChild("big_idle_0").gameObject.GetComponent<Animator>();
AnimatorStateInfo currentState = test.GetCurrentAnimatorStateInfo(0);
animationTime = currentState.normalizedTime;
targetTime = ((TWA + 180) / 360) * currentState.length;