Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 /
This question was closed Nov 27, 2012 at 06:45 PM by davidflynn2 for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by davidflynn2 · Nov 26, 2012 at 10:57 PM · c#gameobjectdeactivate

Deactivate gameobject and all children

I there any way in C# that you can deactivate a game object and all its children. I have a game object that has like 25 children I want to deactivate that gameobject and all of its children.

Comment
Add comment
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

2 Replies

  • Sort: 
avatar image
1
Best Answer

Answer by flaviusxvii · Nov 26, 2012 at 11:06 PM

http://docs.unity3d.com/Documentation/ScriptReference/GameObject.SetActive.html

Comment
Add comment · Show 4 · 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 davidflynn2 · Nov 26, 2012 at 11:18 PM 0
Share

I get this Error. error CS1061: Type `UnityEngine.GameObject' does not contain a definition for `SetActive' and no extension method `SetActive' of type `UnityEngine.GameObject' could be found (are you missing a using directive or an assembly reference?)

avatar image flaviusxvii · Nov 26, 2012 at 11:49 PM 0
Share

Are you using an older version of Unity? You used to just set gameObject.active = false. Or whatever you needed to do. That's deprecated in Unity 4.

avatar image Loius · Nov 27, 2012 at 12:08 AM 1
Share

The Unity3 equivalent is gameObject.SetActiveRecursively(true or false)

avatar image davidflynn2 · Nov 27, 2012 at 06:32 PM 0
Share

Ok thanks so much your bottom commet is what I was needing.

avatar image
-1

Answer by sparkzbarca · Nov 26, 2012 at 11:50 PM

the parent transform contains an implicit list of children.

foreach (transform child in parent.transform) { child.gameobject.enable = false; }

Thats the most elegant way i think.

Mark as answered :)

Comment
Add comment · Show 1 · 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 flaviusxvii · Nov 26, 2012 at 11:52 PM 0
Share

Except GameObject doesn't have an "enable" datamember.

Follow this Question

Answers Answers and Comments

13 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Activating/Deactivating GameObject Problem :( 3 Answers

How do I call an animation event on a deactivated gameobject in unity3d c# 0 Answers

How to activate/deactivate a component(Animator) when a specific game object was activated 0 Answers

Distribute terrain in zones 3 Answers


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