• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by user-6774 (google) · Nov 25, 2010 at 03:18 AM · gameobjectmouselook

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

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image user-6774 (google) · Nov 25, 2010 at 03:46 AM 1
Share

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?

3 Replies

· Add your reply
  • Sort: 
avatar image
8

Answer by Jean-Fabre · Nov 25, 2010 at 06:37 AM

Hi,

Look for

gameObject.SetActiveRecursively(false);

This is maybe what you need.

Bye,

Jean

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
4

Answer by Statement · Dec 11, 2010 at 09:37 AM

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.
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image cregox · Sep 06, 2011 at 06:03 PM 0
Share

For just hiding the object: http://answers.unity3d.com/questions/14165/show-and-hide-a-prefab-or-gameobject.html

avatar image cowlinator · Apr 04, 2012 at 11:16 PM 0
Share

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

avatar image
0

Answer by flamy · Nov 15, 2011 at 10:23 AM

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!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

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

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

Mouselook script beserk when GO made child 0 Answers

Accessing RigidbodyFirstPersonController 0 Answers

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

Game freezes everything when calling WaitForSeconds 1 Answer

Rigged Mesh shows in game view but not on Phone after build 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges