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

Hi,

Look for

gameObject.SetActiveRecursively(false);

This is maybe what you need.

Bye,

Jean

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.

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!