x


Is there a quick way to de-activate a game object and all its children in script?

Basically from script, I can set active to false for a game object, but can I do it in sucha way that all its children also get de-activated?

Iterating through children is cumbersome and involves al ot of duplicate code...

more ▼

asked Oct 22 '11 at 09:18 AM

chillypacman gravatar image

chillypacman
203 51 67 75

Be sure to tick and vote for Aldona's awesome and fast answer!

Oct 22 '11 at 09:37 AM Fattie
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

You can use SetActiveRecursively, like this:

gameObject.SetActiveRecursively(false); // deactivate this object and children

If it's other object, just use its GameObject reference:

var other: GameObject;

    other.SetActiveRecursively(true); // activate "other" and its children
more ▼

answered Oct 22 '11 at 09:28 AM

aldonaletto gravatar image

aldonaletto
42.5k 16 43 202

(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:

x4374
x123
x5

asked: Oct 22 '11 at 09:18 AM

Seen: 1780 times

Last Updated: Oct 22 '11 at 09:37 AM