Back to Writing
NOTESunitycoroutinedebugging

Unity Coroutine Stop Patterns: Why StopCoroutine Doesn't Always Work

August 30, 2019Updated Feb 17, 2026

Post image

You start a coroutine with StartCoroutine("Test") and stop it with StopCoroutine("Test"), but it often doesn't stop as expected.

String-based StopCoroutine only works reliably when the coroutine reference isn't recreated within the same execution flow.

For example, calling start/stop immediately in the same function works fine:

void A()
{
   StartCoroutine("Test");
   StopCoroutine("Test");
}

Or starting in one function and stopping via string in another — as long as the same execution flow is maintained — can also work:

void A()
{
   StartCoroutine("Test");
   B();
}

void B()
{
   StopCoroutine("Test");
}

However, in most real-world code, the coroutine instance gets recreated, which is why the string-based approach often fails.

The safe pattern is to store the IEnumerator reference and stop using that same instance:

IEnumerator co = A();

StartCoroutine(co);
//---------------------------
StopCoroutine(co);

//------------------------
IEnumerator A()
{
yield return null;
}