- Home /
WaitUntil and WaitWhile don't work
For some reason in my script, the WaitWhile and WaitUntil does not work properly. I am trying to wait until the animation is "DropBuilding" and then wait while it is not finished. Sometimes, the code just stops there when the animation has already finished playing and nothing happens. Here is the code:
Debug.Log("Animation starting to play.");
// Waits until the current animation is DropBuilding.
yield return new WaitUntil(() => previewAnimator.GetCurrentAnimatorStateInfo(0).IsName("DropBuilding"));
// Waits till animation has finished playing.
yield return new WaitWhile(() => previewAnimator.GetCurrentAnimatorStateInfo(0).normalizedTime >= 1f);
Debug.Log("Animation has finished.");
Answer by Bunny83 · Jul 08, 2018 at 09:47 AM
You probably destroyed or deactivated the gameobject the coroutine runs on. This will naturally stop / terminate all coroutines that run on that gameobject.
This is all we can guess here as your question is lacking context.
I am just trying to wait till animation finishes, thats all. Only after the animation is finished the method can continue. This works most of the time, but sometimes it just doesn't work for some reason.
Your answer
Follow this Question
Related Questions
Play animation then destroy gameOject C# "SOLVED" 1 Answer
Detecting last frame of animation, without StateMachineBehaviours or Animation Events 0 Answers
Animator.GetCurrentAnimatorStateInfo(0).IsName("FallOffBed") unexpectedly returns false 0 Answers
Coroutine not working ? possible errors ? 1 Answer
Ienumerator wait for event 0 Answers