GetComponent<Animtation>() is always null

I must be doing something wrong here. I have a UI.Panel with an Animator component. I’m trying to get access to the animation so I can control play & stop in code.

Here’s what I’ve tried in the script called Star
var anim = GetComponent();
if (anim == null)
anim = gameObject.GetComponent();
if (anim == null)
anim = this.gameObject.transform.GetComponent();

if (anim == null)
anim = transform.GetComponent();

var xyz = GetComponent();
if (anim == null)
anim = xyz.GetComponent();

if (anim == null)
Debug.Log(“anim is null”);
else
Debug.Log(“found animation”);

I can’t figure out what I’m doing wrong.

Looks to me that there’s an Animator Component. Not sure why you’re trying to get an Animation Component.

I’m using the Animation window to create the animation so I thought I would be able to get the underlying animation component.

Nope. Your screenshot says you have an Animator component on that object, so you can only cast to an Animator component. Either use an Animator component or an Animation component. I don’t think they’re intended to be used in conjunction, nor do I think they’re used in the same situation.