Unity 2019.3.13f1: issue with Animator.SetTrigger in script

I have setup a very simple animation for a scene transition fade out / fade in.
The animation themselves work.
If I click the trigger while in play mode, it works.
If I call the “SetTrigger” API, it does not work.
The default transition (FadeIn) does actually work.

    void Start()
    {
        anim = GetComponent<Animator>();
    }

    public void LoadScene()
    {
        StartCoroutine(Transit());
     
    }

    IEnumerator Transit()
    {
        anim.SetTrigger("FadeOut");
        yield return new WaitForSeconds(anim.GetCurrentAnimatorClipInfo(0).Length);
        SceneManager.LoadScene(NextScene);
    }

SceneManager.LoadScene(NextScene); is called and works, only the “SetTrigger” does not.

If you have any idea what could go wrong, I would be interested.

As a side note, I was using Unity 2019.3.12f1 when I first started to setup this transition animation.
Nothing was working at all, I could not even see the Animator transition screen. Lost hours trying to understand what I was doing wrong. In the end I was not doing anything wrong.
Upgrading to Unity 2019.3.13f1 solved this part of the issue.

(Earlier this year I also add issues with the animator, and again it was a bug in the specific Unity version I was using at the time).

The current clip/state info will still be whatever was previously playing so if you want to get the length of the new animation you need to wait a frame first.

If you would prefer to avoid stupid bugs like this and allow your scripts to directly play whatever AnimationClip you want without needing an Animator Controller, you should check out Animancer (link in my signature).

I’m a bit late on this.
Thanks for the answer, but my issue was not on getting the length but the animtion to actually run on the SetTrigger call.

In the end I solved the issue by placing the animator component on the object it was animating.
When placed on another object, for whatever reason, the default animation was running, but not the triggered one. The fact that the default animation was running mislead me thinking it was ok to place it on another object.
When placed on the animated object, everything is running fine.