x


GameObject.active not deactivating all children

Just wondering about how GameObject.active works? Currently I have a small demo using the first person controller prefab where I can walk around a room.

If I set the first person controller object's active member to false it still seems to be running the MouseLook script. All other scripts attached to the object appear to be disabled.

Has anyone else had this problem? I tried pulling out the MouseLook script and deactivating it directly by going GetComponent().enabled = false but that didn't seem to work.

I'm pretty sure there are no other instances of the script running.

Any Ideas?

Thanks

more ▼

asked Nov 25 '10 at 03:18 AM

user-6774 (google) gravatar image

user-6774 (google)
17 1 1 1

sorry there are actually 2 instances of the script. One on the capsule and one on the camera. But shouldn't setting its active member to false should deactivate all of the children?

Nov 25 '10 at 03:46 AM user-6774 (google)
(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

Hi,

Look for

gameObject.SetActiveRecursively(false);

This is maybe what you need.

Bye,

Jean

more ▼

answered Nov 25 '10 at 06:37 AM

Jean Fabre gravatar image

Jean Fabre
3.1k 68 75 103

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

Just wondering about how GameObject.active works?

GameObject.active disables or enables scripts and components running on the game object as well as making it not appear in most object searches such as GameObject.FindWithTag while disabled.

  • Note: It is not the same as hiding an object, which some people seem to believe, altough it will hide the object among other things. If you just want to hide an object but still have its scripts running, disable only its renderer.

I don't know if there are certain scripts that can be run while it is disabled, I dont think so but for the sake of completeness See note about MonoBehaviours enable.

Note: The checkbox for disabling a MonoBehavior (on the editor) will only prevent Start(), Awake(), Update(), FixedUpdate(), and OnGUI() from executing. If none of these functions are present, the checkbox is not displayed.

  • It is also likely that you have only disabled one game object out of an hierarchy of game objects. Make sure the correct game object is disabled. GameObject.SetActiveRecursively can disable an hierarchy of objects.
more ▼

answered Dec 11 '10 at 09:37 AM

Statement gravatar image

Statement ♦♦
20.1k 35 70 175

OnCollision() still runs when a script is disabled, I believe

Apr 04 '12 at 11:16 PM cowlinator
(comments are locked)
10|3000 characters needed characters left

SetActiveRecursively sets the whole game object to the defined state... but gameObject.active will only turn the parent on and the children will be in their previous state only thats what ur prob. is!

more ▼

answered Nov 15 '11 at 10:23 AM

flamy gravatar image

flamy
3.5k 5 11 37

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

x2097
x162

asked: Nov 25 '10 at 03:18 AM

Seen: 10930 times

Last Updated: Apr 04 '12 at 11:16 PM