If you apply a StopAllCoroutines() in a script to StopAllCoroutines is there a way to re enable All Couroutines again?

Any help would be appreciated.
Im still learning here. Thanks.

You would call StartCouroutine(MyCouroutine()); to start each one again.

In short: No, there is no method to do this automatically since “StopAllCoroutines” does not just halt / disable running coroutines, but it actually remove all running coroutines entirely. So they are gone after they are stopped.

If you’re searching for a way to stop all coroutines in order to halt them so they can be resumed later, this is only partially possible. You would need to store all the IEnumerator objects of all your coroutines in a List. Note that when a coroutine is stopped it will always left at the last executed yield statement. This last yield statement is essentially lost when you resume the coroutine. So if you have a coroutine that has a yield return new WaitForSeconds(5000); in a coroutine and you stopped the coroutine while it was waiting at that point, when you resume the coroutine, it will continue after that yield statement.

private List<IEnumerator> m_Coroutines = new List<IEnumerator>();

public Coroutine StartResumableCoroutine(IEnumerator aCoroutine)
    return StartCoroutine(aCoroutine);

public void ResumeAllCoroutines()
    foreach(var item in m_Coroutines)

Note that this is just a proof of concept and not a general solution. This has several issues. If you start a coroutine using StartResumableCoroutine instead of StartCoroutine that coroutine will be stored in the list. So this should not be used for coroutines which are started several times since they are never removed from the list.

Also as mentioned before resuming a coroutine that yielded any special value might cause errors or unexpected behaviour. You should only use this on coroutines which use yield return null; or if you don’t mind loosing the last yield value. For example yielding on a WWW object and then stopping / resuming would produce an unpredictable result. If you stopped and resumed the coroutine too early, the request wasn’t done yet so the code that follows the yield statement wouldn’t work correctly and might throw exceptions.

Thanks for your input I will study this. :slight_smile: