- Home /
Question by
jeanlucthumm · Aug 04, 2017 at 07:05 PM ·
destroycoroutinedestroy objectcancel
Destroying an object with running coroutine
Say you have the following two classes:
public class A : MonoBehavior {
public IEnumerator HandleEvent(...) {...}
}
public class B : MonoBehavior {
private A _a = new A();
public Sample(...) {
StartCoroutine( _a.HandleEvent(...));
Destroy(_a);
}
}
What would happen to the coroutine if you called Sampel()?
Comment
Best Answer
Answer by Timo326 · Aug 04, 2017 at 08:31 PM
I think it would stop, because a coroutine is not a seperate process or threat.
But this is only an idea
Answer by Master_Zen · Aug 12, 2018 at 08:48 PM
After testing this with an object that logs something to the console every frame via a coroutine and then destroying it shortly after the scene was loaded, i can say that coroutines that run in script attached the the destroyed object will stop when the object is destroyed.
Your answer
Follow this Question
Related Questions
Prevent destruction of an object's child 1 Answer
Collision Detection not working? 1 Answer
Cancel IEnumerator in progress 3 Answers