• 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

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

Activating/Deactivating GameObject Problem :( 3 Answers

Multiple Cars not working 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges