x


Does deactivating a GameObject automatically stop its coroutines?

If I call

gameObject.active = false

from within my behavior script, does this automatically stop all running coroutines on the object?


Long winded background:

I've got a component attached to a GameObject that implements my game's rules through a series of coroutines. Essentially, it boils down to "do stuff, wait a few seconds, do more stuff".

Sometimes, I want to pause this object, run the rules on a different object, then resume the original object. I was hoping that I could achieve this by activating and deactivating the appropriate objects, but reactivating the first object doesn't resume the old coroutines.

more ▼

asked Nov 16 '10 at 07:03 AM

CapnCromulent gravatar image

CapnCromulent
226 1 1 8

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

Ok, wading through answers tagged with "active" revealed the answer (whereas those with coroutine did not, strangely).

Yes, deactivating an object kills its coroutines. I may try disabling just the component instead. More details in this Q&A.

more ▼

answered Nov 16 '10 at 07:07 AM

CapnCromulent gravatar image

CapnCromulent
226 1 1 8

(comments are locked)
10|3000 characters needed characters left

Yes (as noted already)

You can use OnEnable() to start the co-routine back up if needed: http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.OnEnable.html

more ▼

answered Aug 01 '11 at 12:37 AM

Rafes gravatar image

Rafes
305 6 8 13

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2083
x323
x113

asked: Nov 16 '10 at 07:03 AM

Seen: 2373 times

Last Updated: Aug 01 '11 at 12:39 AM