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 oliver-jones · Jan 16, 2014 at 11:48 AM · rendererloopreferenceactive

Turning On & Off Renderers

Hello,

I have a game empty that has a load of game objects in it. I want to turn this empty off so that all the children will not be visible. Although, I don't want to use SetActive(false), as this will shutdown the scripts too. I only want to turn off the renderers.

I also want the ability to turn them back on too, only issue is that by default, some game objects have their renderers turned off anyway, so I need to make a system that will check if they were already turned off, before being turned off, when being turned on... :/

So I firstly need to reference all the renderers that are already turned off to being with by putting them all into an array, before turning off the renderers. Once done, I can turn off all the renderers (even the ones that are already turned off, as it doesnt matter).

Then, then turning them on, I need to check my referenced renderers against the current renderer in the loop, if they match, then leave them off, otherwise, turn them back on.

 //turn on and off renderers, but ONLY the ones that were turned on to being with
 var alreadyTurnedOff = new Array();
 function TableRenderer(on : boolean){
 
     var renderers = gameContent.GetComponentsInChildren(Renderer);
 
 
     for(var r : Renderer in renderers){
 
         //turn off renderers, make sure we reference the ones that are already turned off - so we dont turn them on when activating
         if(on == false){
 
             //removed cached renderers
             alreadyTurnedOff.Clear();
 
             if(r.enabled == false){
                 alreadyTurnedOff.Add(r);
             }
 
             r.enabled = false;
         }
 
         //only turn on the non reference objects
         if(on == true){
 
             for(var i = 0; i < alreadyTurnedOff.length; i++){
 
                 if(r == alreadyTurnedOff[i]){
                     //leave off
                 }
                 else
                     r.enabled = true;
             }
         }
     }
 }

Issue is, it doesn't work! All my renderers still turn on, no matter what?!

Comment
Add comment · Show 2
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 felixpk · Jan 16, 2014 at 01:49 PM 0
Share

How about adding a script to the children? Like they check wether the Parents Empty is enabled or not?

For example:

 if(parent.renderer.enabled == true){
    this.renderer.enabled = true;
 }else{
    this.renderer.enabled = false;
 }

And then define in the start() if this child is influenced, or just dont add the script. I don't know if this matches your problem ...

avatar image Calum-McManus · Jan 16, 2014 at 02:45 PM 0
Share

Here's an idea, you have a Empty GameObject with ally our scripts, you then add another empty as a child to the first, then have all the other object as a child to that one, then simple "SetActive(false)" to the second empty? Sounds like it would work!

1 Reply

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

Answer by craigaw · Jan 17, 2014 at 05:21 AM

There are a couple of small errors in yours. This works for me,

 private var alreadyTurnedOff : Array = new Array();
 function TableRenderer(on : boolean) {
     var renderers : Renderer[] = gameObject.GetComponentsInChildren.<Renderer>();
 
     if (on) {
         for ( var r : Renderer in renderers) {
             r.enabled = true;
         }
         for ( var o : Renderer in alreadyTurnedOff) {
             o.enabled = false;
         }
     } else {
         alreadyTurnedOff.Clear();
         for ( var r : Renderer in renderers) {
             if (!r.enabled)
                 alreadyTurnedOff.Push(r);
 
             r.enabled = false;
         }
     }
 }
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

21 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Change gameobject sprite with button 1 Answer

need help resolving 'renderer.material.color' conflict. 3 Answers

Changing two different objects renderer colour 1 Answer

How to deactivate all GameObject in a array, except last one 4 Answers

Can't add multiple integers to a List in a Loop! 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