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 Draco18s · Apr 01, 2013 at 07:58 PM · javascript

Disabling all renderers in Hierarchy

 var renders : Renderer[] = gameObject.GetComponentsInChildren(Renderer);
 Debug.Log("Num renderers: " + renders.length);
 for (var rend : Renderer in renders) {
     rend.enabled = false;
 }

This throws an error:

 InvalidCastException: Cannot cast from source type to destination type.
 ChangeSize.Start () (at Assets/Scripts/AboveCode.js:1)

Excuse me, but Renderer is of type Component, yes you CAN make that cast. I mean, hell, that code is copied from the documentation's example on using GetComponentsInChildren, only using the Renderer instead of the HingeJoint (which also inherits from type Component).

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by AlucardJay · Apr 01, 2013 at 08:11 PM

I had the same problem, but found this (check the last post) : http://forum.unity3d.com/threads/143049-Need-to-disable-all-Renders-in-Children-Objects

 gameObject.GetComponentsInChildren.< Renderer >();

Try using this syntax :

 function DisableAllRenderers() 
 {
     var allRenderers : Renderer[];
     allRenderers = gameObject.GetComponentsInChildren.< Renderer >();
     for ( var childRenderer : Renderer in allRenderers )
     {
         childRenderer.enabled = false;
     }
 }
Comment
Add comment · Show 5 · 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 Draco18s · Apr 01, 2013 at 08:21 PM 0
Share

Trying that now. And... No compile errors, but it's not disabling them on start. The same function call later in the program (that hides the model after it's "closed") does function correctly.

avatar image AlucardJay · Apr 01, 2013 at 08:24 PM 0
Share

Try function Awake() ins$$anonymous$$d of Start, maybe the object has not yet initialized (just a guess).

Or try Invoke( "DisableAllRenderers", 0.02 );

avatar image Draco18s · Apr 01, 2013 at 08:25 PM 0
Share

Nope. Didn't work there either. I can see how many renderers there are (154--I need to get my modeler to reduce that number!), so it is running, it's just not disabling them.

Edit:

Ok this is weird. I manually disabled them all so that they were disabled by default.

Something turned them on. o..O

Redit: Oh, I know what's doing it. $$anonymous$$ram AR plugin. >..<

avatar image AlucardJay · Apr 02, 2013 at 05:50 AM 0
Share

That is good you found the problem and what was causing it. I was a little worried that you had this not disabling on start problem, when you could disable once everything was running. Definitely if another script is enabling them, there's the problem. So my answer with the correct syntax for finding all children renderers is proven working now I hope.

avatar image Draco18s · Apr 02, 2013 at 12:14 PM 0
Share

Yeah, I forgot that the AR plugin turns off all the renderers at start (but oddly, when it loses its tracker, it doesn't disable them again).

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

11 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

Related Questions

About "SplineController" Javascript 1 Answer

What is wrong with this script? 0 Answers

If statement only work once? 1 Answer

how to use matrice with unity 3D 1 Answer

[Solved] Generating Particles with Attack Animation 1 Answer


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