Search Unity

This seems risky what could go wrong?

Discussion in 'Scripting' started by ZyngaStef, Nov 25, 2015.

  1. ZyngaStef

    ZyngaStef

    Joined:
    Oct 9, 2014
    Posts:
    2
    In a coroutine we have the following:

    animator.Play("anim");

    while (!animator.GetCurrentAnimatorStateInfo(0).IsName("anim"))
    {
    yield return null;
    }
    while (animator.GetCurrentAnimatorStateInfo(0).IsName("anim"))
    {

    yield return null;
    }

    We have a case where the game would not progress one time, and I can reproduce it if I put a delay in the first while loop that is longer than the animation which is 2.5 seconds long, so the animation has ended so the first while loop never exits and we lock up.

    Is it possible that after the first yield Unity would not return to this code for more than a few seconds, after the animation has finished thus getting stuck in the loop?

    In anycase we are replacing with cleaner code,
     
  2. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,791
    Animator changes state after this code runs, so it gets in the first while for at least one frame. If you delay it in there for as long as it takes for the first while to return to being true, it never gets out of it.