Skip to main content

Coroutine Runner

The CoroutineRunner is an utility runtime tool that can be used to run coroutines from non-MonoBehaviour classes or without the need to keep the MonoBehaviour caller instantiated and enabled. It can be used as follows:

IEnumerator MyCoroutine()
{
...
}

...

Coroutine myCoroutine = CoroutineRunner.Start(MyCoroutine());

Exactly like normal Coroutines, they can be stopped individually or completely by calling

CoroutineRunner.Stop(myCoroutine); // Stops individual coroutines
CoroutineRunner.StopAll(); // Stops all coroutines on the runner
warning

Calling CoroutineRunner.StopAll() stops all running coroutines, including those that might have been started elsewhere. Use it sparingly and only if necessary.