Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Bug [Working Now] Animation Events Do Not Run Code After The First Yield Of Coroutine

Discussion in 'Animation' started by Ghosthowl, Oct 20, 2023.

  1. Ghosthowl

    Ghosthowl

    Joined:
    Feb 2, 2014
    Posts:
    228
    If you make an animation event in the FBX of a 3D model, the event function cannot run any code past the first yield of a Coroutine created within that function. So basically the Coroutine does not work at all.

    Is this by design and if so why?
     
  2. Kybernetik

    Kybernetik

    Joined:
    Jan 3, 2013
    Posts:
    2,496
    I've never seen any indication that Animation Events are intended to be able to start coroutines and what you're seeing is the same thing that happens if you try to call a coroutine like a regular method. Just have the event call a regular method which calls StartCoroutine properly.
     
    Ghosthowl likes this.
  3. Ghosthowl

    Ghosthowl

    Joined:
    Feb 2, 2014
    Posts:
    228
    Ah. I can see where what I was stating might be misunderstood. I meant the following example:
    Code (CSharp):
    1.     private void AnimationEvent()
    2.     {
    3.         StartCoroutine(ImACoroutine());
    4.     }
    5.    
    6.     private IEnumerator ImACoroutine()
    7.     {
    8.         //Code here will run
    9.         Debug.Log("I will run!");
    10.         yield return new WaitForEndOfFrame();
    11.         //Code below this will not run
    12.         Debug.Log("I will not run!");
    13.     }
    I'm not sure what happened, but the code now works for me - so thank you for getting me to re-test it. I've been dealing with a series of race conditions when it came to IK so perhaps something got busted there. My code and setup have since changed so I am unsure what happened here.
    I will say this is not the first time such a thing has happened to me when it comes to starting Coroutines from more obscure places within a big project.