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 /
avatar image
0
Question by maynull · Feb 26, 2013 at 03:38 PM · gameobjectunity4setactiverecursivelygameobject.active

Unity 4 SetActive - SetActiveRecursively parent-child trouble

Hello,

Now since setActiveRecursively obsolete in Unity4 I'm trying to change all lines I used after upgrading the project.

I have a problem with cases like below How do you do the same job? this.gameObject.SetActiveRecursively(false); this.gameObject.active = true;

Actording to Unity 3.5 to 4 guideline they say "setting GameObject.active is equivalent to calling GameObject.SetActive(). Calling GameObject.SetActiveRecursively() is equivalent to calling GameObject.SetActive() on the GameObject and all of it's children."

So from looking here it should be this.gameObject.SetActive(false); this.gameObject.SetActive(true); which is nonsense

Should I loop all children and make them SetActive false? -- again I think nonsense..

So if you have any idea or solution please share Cheers

Comment
Add comment · Show 3
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 Ranger-Ori · Feb 26, 2013 at 04:14 PM 0
Share

I personally used SetActive, ins$$anonymous$$d of SetActiveRecursively and it Enabled/Disabled all the children objects too. Don't loop, just use SetActive(false) to the parent.

avatar image maynull · Feb 26, 2013 at 04:24 PM 0
Share

Don't think you got what I meant. If you don't loop than how can you only activate the parent and let all children stay deactive. It's not possible...

avatar image Tarlius · Feb 26, 2013 at 04:26 PM 0
Share

This question might help.

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by hoy_smallfry · Feb 26, 2013 at 04:15 PM

I'd say you should loop through all the immediate children and call SetActive() on them. Immediate children are the ones directly connected to the parent, so if you turn them inactive, should achieve the same effect. Yes, its a little ridiculous, but so was having to call gameObject.SetActiveRecursively(false); gameObject.active = true;.

To modify just the immediate children:

Javascript:

 for (var child : Transform in transform)
 {
     child.gameObject.SetActive(false);
 }

C#:

 foreach (Transform child in transform)
 {
     child.gameObject.SetActive(false);
 }
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 maynull · Feb 26, 2013 at 04:22 PM 0
Share

Thank you.. Seems like that's the only way for now. Still not sure why Unity made that change in the first place. Doing SetActive manually probably costs more performance than using SetActiveRecursively..

avatar image hoy_smallfry · Feb 27, 2013 at 04:08 PM 0
Share

is this question closed then?

avatar image
0

Answer by Xaon · Aug 20, 2013 at 04:38 PM

There are gameObject.activeSelf and gameObject.activeInHierarchy. I haven't used those yet but they might solve similar problems. Here is the big explanation for those who are migrating from 3.5 version: http://docs.unity3d.com/Documentation/Manual/UpgradeGuide3540.html

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.

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

SetActiveRecursively(true) replacement in Uinity4. 2 Answers

SetActiveRecursively not activating children 2 Answers

gameObject.SetActiveRecursively 1 Answer

Activating gameObject issue... 1 Answer

Game object follow path of other game object 2 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