coroutine deaths in Unity are almost always one of three things: the GameObject gets disabled, the MonoBehaviour gets destroyed, or you're yielding inside a try/catch and an exception is silently swallowing the iterator state.
the try/catch one is the sneaky one. this pattern looks fine but will silently kill the coroutine if anything throws inside the loop:
IEnumerator MyRoutine() {
while (true) {
try {
DoSomethingRisky();
} catch (Exception e) {
Debug.LogError(e);
}
yield return null; // this line is OUTSIDE the try, so it's okay
}
}
if the yield is inside the try block, Unity can't resume it after a throw. move all your yields outside try blocks and a lot of mysterious coroutine deaths just stop happening.
