What happens when calling StopCoroutine on a Coroutine that is awaited somewhere else ?
Hello,
I'm currently having a mechanism where I start a Coroutine inside a Coroutine, and then wait for it to finish to reset some values.
It looks like something like this :
private IEnumerator StartBehaviour()
{
_currentBehaviour = StartCoroutine(behaviour.StartBehaviour());
yield return _currentBehaviour;
// Resetting values
}
This is happening in an enemy AI everytime it has to execute a behaviour.
The thing is, the current behaviour can be interrupted, to react to some of the player's actions, with a :
StopCoroutine(_currentBehaviour)
So the question is, what happens to the coroutine StartBehaviour
in this case ? I tried to investigate with the debugger, and it seems that it doesn't resume it's execution like it would if _currentBehaviour
finished executing normally.
Is StartBehaviour
terminated at the same time as _currentBehaviour
? Or does it keep waiting until the end of times ?
Thank you for your help !
Your answer
![](https://koobas.hobune.stream/wayback/20220612230027im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Coroutine Error when Capturing 360 Video 0 Answers
Why Unity docs do not use New with WaitForSeconds and yield? 1 Answer
Smooth Forward Movement with a CoRoutine 1 Answer
Heavy use of Unity API & UI Thread 0 Answers
If a variable used by a coroutine is changed, will the coroutine know while it is running? 1 Answer