The question is answered, right answer was accepted
Coroutine Not Starting - Crashes Instead?
I have been trying to solve this for hours and I have looked at every Unity and StackOverflow answer regarding Infinite Loops, Coroutines, and threading, and have tried eons of methods, but to no avail. Funny, cause that is what everyone else says regarding their own particular infinite loops, and I am no exception now.
I have a countdown timer that goes 3...,2...,1...,GO!.
I start the process in the Start() method by calling the first Coroutine, then it moves down like a chain. The code freezes up and crashes right whenever the "EndGo_StartTicker" Coroutine should begin.
private void Start ()
{
StartCoroutine (End3_Start2 ());
}
private IEnumerator End3_Start2 ()
{
yield return new WaitForSeconds (1);
countdownTimer [0].gameObject.SetActive (false);
countdownTimer [1].gameObject.SetActive (true);
StartCoroutine (End2_Start1 ());
yield return null;
}
private IEnumerator End2_Start1 ()
{
yield return new WaitForSeconds (1);
countdownTimer [1].gameObject.SetActive (false);
countdownTimer [2].gameObject.SetActive (true);
StartCoroutine (End1_StartGO ());
yield return null;
}
private IEnumerator End1_StartGO ()
{
yield return new WaitForSeconds (1);
countdownTimer [2].gameObject.SetActive (false);
countdownTimer [3].gameObject.SetActive (true);
StartCoroutine (EndGo_StartTicker ());
yield return null;
}
private IEnumerator EndGo_StartTicker ()
{
yield return new WaitForSeconds (1); //Never gets past here??
countdownTimer [3].gameObject.SetActive (false);
countdownTimer [4].gameObject.SetActive (true);
StartCoroutine (TickerAttribues ());
yield return null;
}
private IEnumerator TickerAttribues ()
{
yield return new WaitForSeconds (1);
SetCountdownDoneToTrue ();
//UnpauseGame ();
countdownTimer [4].gameObject.SetActive (false);
yield return null;
}
Any ideas on how to fix this? Let me know, please, if you need more information or details. Thank you!
Answer by Cuttlas-U · May 28, 2017 at 12:28 PM
hi; why u don't do all of these in one corutine ? ; u can wait many times as u want in one corutine and no need to start different ones; and the reason that it is crashing maybe cause of that Gameobject 4 is activating and there is some thing attached to it that make that crash thing;
How would you put all these into one Coroutine? Just continually yield after 1 second? @Cuttlas-U
Solved! It was conflicting with another Coroutine in another file I completely forgot about. All I had to do was sleep on it and it was the first thing I thought of this morning. Thank you for responding anyways sir!
Follow this Question
Related Questions
Unity Editor can't find IEnumerated 2 Answers
IEnumerator instead of LateUpdate in unity 1 Answer
IEnumerator inner functions 0 Answers
"Can't add script behaviour AICharacterControl. The script needs to derive from MonoBehaviour!" ? 2 Answers
"Can't add script behaviour AICharacterControl. The script needs to derive from MonoBehaviour!" ? 0 Answers