- Home /
Coroutine stopping before it is complete
I have a coroutine that starts other coroutines and waits for them to complete in order for them to animate sequentially. However, the coroutine stops half way through and I don't know why. (I am not calling StopCoroutinesAllCoroutines() anywhere). Any idea why?
public IEnumerator ShowPreGameScreen(bool animated, bool waitForCompletion)
{
print ("Got Here 1"); // <-- prints
yield return StartCoroutine(preGameScreen.Show(animated, waitForCompletion)); // <-- executes
print ("Got Here 2"); // <-- does NOT print
yield return StartCoroutine(ShowTopBar(animated, waitForCompletion)); // <-- does NOT execute
print ("Got Here 3"); // <-- does NOT print
}
Can you show us what's happening in preGameScreen.Show() ?
Here you go:
public virtual IEnumerator Show(bool animated, bool waitForCompletion){
PrepareForShow();
if(animated){
if(showAnimation == null){
print ("You are trying to Show a Screen with a null Show animation. Add a Show Animation to your Screen.");
panel.gameObject.SetActive(true);
yield break;
}
ActiveAnimation.Play(animations, showAnimation.name, AnimationOrTween.Direction.Forward, AnimationOrTween.EnableCondition.EnableThenPlay,
AnimationOrTween.DisableCondition.DoNotDisable);
if(waitForCompletion){
yield return StartCoroutine(WaitForAnimationComplete(showAnimation));
}
}
else{
panel.gameObject.SetActive(true);
}
yield break;
}
There is a chance that WaitForAnimationComplete() hasn't finished yet/ever ? Can you confirm that that coroutine is finishing?
Somehow the problem came back. here:
IEnumerator WaitForAnimationComplete(AnimationClip clip){
if(animations == null) yield break;
if(clip == null) yield break;
print ("Waiting for animation completion: " + clip.length + " secs"); // Gets printed with 0.16667 as clip length
yield return new WaitForSeconds(clip.length); // Never comes back from it!
print("Done"); // Does NOT get printed!
}
Answer by Filippopotamus · Jun 28, 2013 at 07:15 PM
Derp. Found the problem. My "WaitForAnimationComplete()" function was getting stuck. Now why animation.IsPlaying returns true forever I don't know. But that was my problem. Sorry for wasting your time.
Funny how you can look over and over at your code and not find the problem. Then the second you post it online you figure it out. Thanks for the help :)