Last active
February 17, 2020 09:58
-
-
Save 20chan/779009dfae67dd1f74fc66e8d90f289d to your computer and use it in GitHub Desktop.
Unity StopCoroutine doesn't work at all in nested Coroutine but it is ambiguous
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using Sirenix.OdinInspector; | |
using UnityEngine; | |
public class DamnUnityCoroutine : MonoBehaviour { | |
private Coroutine coroutine; | |
[Button(ButtonSizes.Large)] | |
public void Go() { | |
coroutine = StartCoroutine(A()); | |
} | |
[Button(ButtonSizes.Large)] | |
public void Stop() { | |
if (coroutine != null) { | |
StopCoroutine(coroutine); | |
} | |
} | |
private IEnumerator A() { | |
while (true) { | |
yield return B(); | |
} | |
} | |
public IEnumerator B() { | |
while (true) { | |
yield return C(); | |
} | |
} | |
private IEnumerator C() { | |
// if line a is alive: StopCoroutine doesn't work | |
// if line b is alive: StopCoroutine works | |
// line `a` | |
yield return D(); | |
// line `b` | |
yield return null; | |
print($"{Time.time}"); | |
} | |
private IEnumerator D() { | |
yield return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://stackoverflow.com/questions/51550499/unity-stopcoroutine-does-not-stop-coroutines-when-there-are-multi-layer-or-nest/51553311#comment90138504_51563210