#the only reason a coroutine won t
1 messages · Page 1 of 1 (latest)
First thing to do is double check which object actually is running the coroutine. Where is the StartCoroutine running?
ahhh
i think i know the problem
im destroying the object OnMouseDown() which is also the script that calls the coroutine.
so i have it being destroyed, then spawning the particle, which is why the coroutine isn't executing fully, am I right in understanding this?
If you are destroying the object that is running the coroutine, the coroutine will stop, yes
you can have the coroutine run on some kind of manager object
yeah that's what im in the process of doing now, moving it to my SpawnManager :)
ok so that seems to not have worked. Does the object that calls the coroutine have to be in existence for the entirety, even if the coroutine called is in a persistent game object?
I think i answered my own question :) .. had to call a method which itself calls the coroutine in another script. Thanks for the help
To clarify things:
- If you do
StartCoroutine(SomeCoroutine());it will start the coroutine on yourself. it's equivalent tothis.StartCoroutine(SomeCoroutine()); - If you do
someObject.StartCoroutine(SomeCoroutine());it will start the coroutine onsomeObject
The source of the coroutine method itself doesn't matter. So:
StartCoroutine(someObject.SomeCoroutine()) Still starts the coroutine on yourself, not someObject. The thing that matters is which object StartCoroutine was called on.
Riiiight
i understand now.
It was the way I was calling it was the issue, so didnt really need to go about it the way I did.. oh well.. I now know for the future :D
I think the approach of making a method which calls StartCoroutine like you did is actually the best and cleanest way.
oh ok, even better then :)