What can cause a coroutine to not being working?

Sometimes my Coroutines just stop working. It’s like if the yield command is just returning from the method and it stop his execution there. Here’s my coroutine, it was working Ok like 2 hours ago. I had opened Unity sometimes already and nothing.

using UnityEngine;
using System.Collections;

public class Transition : MonoBehaviour {
	public ParticleSystem desintegrationParticles;
	public Transform fadeOutTransform;
	public float velocity;
	void Start () {
		StartCoroutine (DesintegrateAndFade () );
	IEnumerator DesintegrateAndFade () {
		Debug.Log("Coroutine started");
		yield return new WaitForSeconds(3);
		Debug.Log("Passed 3 seconds");
		desintegrationParticles.Play ();
		while(fadeOutTransform.position.z > -1) {
		fadeOutTransform.position -= Vector3.forward * Time.deltaTime * velocity;
		yield return null;

I don’t get the “Passed 3 seconds” debug, too.
No errors, no crashes, it’s just not passing from the yield command…

Someone can help me?

*Also, the coroutines aren’t working in the whole project. Where I call the yield command the coroutine just stop his execution, or something like that.

FUTHERMORE: If you call a Coroutine inside object B from object A, then destroy object A, coroutine on object B hangs on yield function (even though object B was not destroyed.)

// THIS will BREAK if the object that calls this IEnumerator is destroyed:
public IEnumerator RandomFunctionA(){
    yield return new WaitForSeconds(1);
    // do stuff

public void RandomFunctionA(){

IEnumerator RandomFunctionACoroutine(){
    yield return new WaitForSeconds(1);
    // do stuff

The only thing you can yield to stop a coroutine is yield break.

Coroutines will stop if the object they are connected to is destroyed. Calls to StopAllCoroutines in another script on the object could halt this one too. I imagine that this script is probably attached to an object that is being destroyed though.

Another reason is if you set Time.timeScale = 0 then
yield return new WaitForSeconds(1.5f)
will not work correctly

I just tried this:

IEnumerator Example () {

float counter = 0;
float target = 5;

while(counter < target) {
counter += Time.deltaTime;
yield return null;


And, fortunatelly it worked! I have some dozens of Coroutines and I’ll probably will need to this this for each of them!

Mike, I know the way I did the yield is not the best way to do it, but it worked, seems like just yield return null is working. But of course WaitForSeconds is a lot better to use and it’s a lot more straight forward, too.

I have coroutines in a lot of objects and everything was working and stopped from one hour to another. The objects aren’t being destroyed, so that’s not what is causing the break of the coroutine.

I can create another script with the simplest coroutine ever and attach to any object (which will not be destroyed until the coroutine was supposed to end his execution ) and nothing happens. If I put a print after 2 seconds, this print is never debugged in the console, for example.

I created another project and pasted the assets on it and it worked, but now I need to set up everything again, which is one more headache.

I just had something very similar to this problem. As posted above, things stop working if the object is destroyed. However, importantly, things also stop working if the object is disabled as well.

My code was as simple as:

IEnumerator Example()
    yield return null;
    Debug.Log("Not printed");

…elsewhere, in the depths of my code, I was disabling the game object this script was attached to. After sorting out that bit of logic to only disable it when the work was all done, everything started working properly again.

This seems to be a bug that can sometimes occur when using WaitForEndOfFrame().

Like @asafsitner, I encountered this issue, and the cause was not destroyed/disabled objects. Even when the object running my coroutine was not destroyed and was enabled, the problem persisted when using

yield return new WaitForEndOfFrame();

However, when using

yield return null;

I had no problem.

This is the code I was using:

IEnumerator routine()


Debug.Log("instance id: " + GetInstanceID());

Debug.Log("this == null? " + (this == null));

Debug.Log(“this.gameObject == null?” + (this.gameObject == null));

Debug.Log("this: " + this);

Debug.Log("this.gameObject.name: " + this.gameObject.name);

Debug.Log("this.gameObject.activeInHierarchy? " + this.gameObject.activeInHierarchy);

Debug.Log("this.enabled? " + this.enabled);

yield return null;


yield return new WaitForSeconds(1f);


yield return new WaitForEndOfFrame();



The game object existed and was enabled and active, and everything except “here3” printed out.

I’ve used Unity Coroutines for years, but I rarely ever use WaitForEndOfFrame. This is the first bug where a coroutine failed like this I’ve ever encountered; so my advice is, avoid using WaitForEndOfFrame.

Hello Dude!!! i was wonder about this topic too, i got some issues about this, this is what i can teach you, i don’t know why, it worked for me!!!

bool CreatedCoroutines = false;

void Update(){
         //create your coroutines here, that's all ....
         CreatedCoroutines = true;

Same here, my yields stopped working.

in my case, a WWW yield would send the request to the server, it reaches the server but the yield never returns (even a yield return null!)

I’m now getting this in Unity 4.
After upgrading to Unity 4 my coroutine worked fine for about a week, then I changed around an enum (completely separate from the coroutine) and the coroutine now mysteriously fails/stops working at a yield return new WaitForSeconds(3f);

Yield return new WaitForSeconds(3f); It can be 3.0f as well. As far as I experienced waitforseconds works best and most reliably with floats.