[Solvedf]Animator is not playing an AnimatorController

Hello guys. I want to change the animation from a Button UI. When I do that I get an error "Animator is not playing an AnimatorController ". I have done the same thing manually, and also from the unity method. But same result.

public void CustomTrigger(string triggerName) {

    Animator anim = this.GetComponent<Animator>();
    if (anim.gameObject.activeSelf)
    {
        anim.SetTrigger(triggerName);
    }
}

It´s because you need to assign the anim file on serialize field where you attached this script!

Ok. Thanks guys. I found what the issue was. I had used the prefab instead of the instance.