- Home /
Coroutine state control
I've got a question about StartCoroutine()
and StopCoroutine()
functions.
When you use a string argument these functions control same coroutine. But if you use enumerator argument like:
StartCoroutine(MyCoroutine());
... some code
StopCoroutine(MyCoroutine());
It doesn't stop the coroutine you've started even if it's the only one running.
Is it intended to be like that? Because function API says:
Stops the first coroutine named
methodName
, or the coroutine stored inroutine
running on this behaviour.
Answer by TimGS · May 14, 2015 at 12:48 PM
Seems like it really is intended to be like that and StartCoroutine(MyCoroutine()) stores a new routine everytime you call this function.
So the only one solution is to store your coroutine in a variable and use it like that:
private Coroutine myRoutine;
myRoutine = StartCoroutine(MyCoroutine());
...
if(myRoutine != null)
StopCoroutine(myRoutine);
Well it's logical behavior. Should've guessed that earlier.
Your answer
Follow this Question
Related Questions
Delay between coroutines 1 Answer
Coroutines WaitForSeconds – uneven spacing 2 Answers
Second Coroutine isn't working Unity 1 Answer
Coroutine Help. 1 Answer
Why doesnt my coroutine ever end? 2 Answers