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 ina · Dec 27, 2010 at 10:07 AM · gameobjectparentchildrendereractive

Child object of another GameObject invisible or inactive @ runtime

How do you disable the render or inactivity of the child object of another object?

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

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Sebas · Dec 27, 2010 at 10:17 AM

You can set the active state of any GameObject and all of its children with SetActiveRecursively You can also find individual children by name like this and disable their renderer individually with

// make the object invisible
renderer.enabled = false;
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 azzogat · Dec 27, 2010 at 10:22 AM 0
Share

Beat me to it by 5 seconds, good job. You should also add that because it only searches in the GO's children it also has the benefit of not slowing everything down to a crawl like Find usually does.

avatar image ina · Dec 27, 2010 at 06:15 PM 0
Share

... unless the game object has LOTS of children!

avatar image ina · Dec 27, 2010 at 06:16 PM 0
Share

does setting an object to be inactive also removes its render?

avatar image Sebas · Dec 28, 2010 at 12:59 PM 0
Share

The renderer itself is never removed unless you specifically remove the component. Deactivating a game object will result in the object not being rendered anymore.

avatar image
0

Answer by SkyCharger001 · May 11, 2018 at 09:30 AM

 Parentobject.transform.localScale = new Vector3(0,0,0)

affects all its children without needing to traverse anything and it allows one to have multiple invisibility-chains without the risk of loosing any of them when one is undone.

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 Harinezumi · May 11, 2018 at 10:04 AM 0
Share

Even though it works, I would really recommend against it. Changing the scale will make all the children recalculate their transforms and their physics, which can be very costly, and they would still be rendered. This means that if you have a special shader, it might not even disable its rendering. Not to mention that all the other scripts would still run.
It is a lot easier to just deactivate the game object or its renderer. Even though SetActiveRecursively() was deprecated in Unity 4 and does not exist anymore, it is pretty easy to write a similar function.

avatar image SkyCharger001 Harinezumi · May 11, 2018 at 10:14 AM 0
Share

but as far as i know this is the only approach that can be used if you have multiple invisibility-chains that could otherwise corrupt each other. (EG: disable "Floor[5]/room[9]" during chapter 2 and disable "Floor[5]"during chapter 3: if one used something like SetActiveRecursively() then undoing the latter would undo the former as well, wether it's desired or not.)

avatar image Harinezumi SkyCharger001 · May 11, 2018 at 11:04 AM 0
Share

I see what you mean, and probably this is why SetActiveRecusively() was removed: a deactivated parent hides all the children as well, so SetActiveRecusively() is unnecessary, in fact, it causes more problems. You can easily achieve the above with calls to SetActive():
- in chapter 2, call SetActive(false) on "Floor[5]/room[9]" to disable it; Floor[5] remains, but room[9] gets hidden
- in chapter 3, call SetActive(false) on "Floor[5]" - the whole Floor[5] will get disabled, including room[9] (which would still be disabled if you enable Floor[5]

Does this make sense, or am I still not seeing the issue?

Show more comments

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

2 People are following this question.

avatar image avatar image

Related Questions

Does renderer.bounds of Parent GameObject include all children meshes that are rendered? 1 Answer

Make a simple tree 1 Answer

how do I get reference to a parent or a child? 2 Answers

How to check parent value instead name value(more details in post) 3 Answers

Display Name Above 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