- Home /
StopAllCoroutines() stops coroutines in other scripts? -- Other behaviours ??
Hello there. Simple and quick question.
The definition of StopAllCoroutines() is :
Stops all coroutines running on this behaviour.
This means it will stop all coroutines in all MonoBehaviour scripts? including scripts attached to other objects?
If answer is YES. I'm not very good at scripting knowledge (learned by my own, i do a lot of complex things, but dont have the base knowledge). Is easy/simple to use another kind of "behaviour"? Or maybe is a stupid question? Some kind of tutorial manual where i can learn about that?
Thanks in advance.
Thanks in advance.
Answer by DanielAllison · Oct 22, 2019 at 06:04 PM
When you run StopAllCoroutines(), it will only stop coroutines that are in the same script so other scripts won't be effected.
As far as documentation, there's some info in the Unity documentation if you haven't already read it.
Note that it is irrelevant where the coroutine code is declared. It's only relevant which $$anonymous$$onoBehaviour you used to call StartCoroutine. The coroutine will run on that $$anonymous$$onoBehaviour no matter where it is defined. So for example when you start a coroutine that belongs to a different script inside "this" monobehaviour, the coroutine will run on "this" monobehaviour
// the started coroutine will run on "this" monobehaviour
this.StartCoroutine(referenceToOtherScript.SomeCoroutine());
Likewise if you have a coroutine defined on "this" $$anonymous$$onoBehaviour but you run it on another $$anonymous$$onoBehaviour instance, it will belong to that other $$anonymous$$onoBehaviour and not this one
// the started coroutine will run on the "referenceToOtherScript" $$anonymous$$onoBehaviour
referenceToOtherScript.StartCoroutine(this.$$anonymous$$yCoroutine());
Your answer
Follow this Question
Related Questions
Avoid using MonoBehaviour just for StartCoroutine or WWW load 0 Answers
Coroutines pauses when not focused on the game page. 1 Answer
StartCoroutine can't be called from a GameObject. Am I late to this party? 2 Answers
Which monobehaviour functions can be defined as coroutine (except Start) 2 Answers