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
3
Question by Rush3fan · Jan 27, 2012 at 04:46 AM · rendererdisablechildren

How do I simply hide an object in Unity?

Of all things, this has me puzzeled. How do I simply just hide an object?

It's not as simple as it sounds.. I need some way to hide an object that has dozens of root meshes inside it.

I have looked into this code:

 // Disable the spring on all HingeJoints 
 // in this game object and all its child game objects
 var hingeJoints : HingeJoint[];
 hingeJoints = GetComponentsInChildren (HingeJoint);
 for (var joint : HingeJoint in hingeJoints) {
     joint.useSpring = false;
 }


But, it's not really set up right.. I don't know.. I keep getting a "InvalidCastException: Cannot cast from source type to destination type." error

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
5
Best Answer

Answer by Lo0NuhtiK · Jan 27, 2012 at 05:35 AM

This isn't really "hiding" objects, so maybe re-word your question-title for search-purposes if you will.

I'm unsure of if this is the "right" way of doing things, but whenever I do stuff like you're trying and if I get those same errors, I just change the variable type to component and it's worked every time (so-far) ... Although, trying it with particles (I think it was particles anyway) did give me "warning" messages, but not errors.
Anyway, give that a shot wherever you're trying it -->

var hinges : Component[] ;
hinges = gameObject.GetComponentsInChildren(HingeJoint) ;
for(var joint : HingeJoint in hinges){
   joint.useSpring = false ;
}
Comment
Add comment · Show 9 · 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 Rush3fan · Jan 27, 2012 at 05:54 AM 0
Share

Well, it sort of is the goal..

So, now I'm trying to select a parent object by assigning the variable in the inspector.

var BodyVisual:Component[];

And then, this is how the code is:

BodyVisual=gameObject.GetComponentsInChildren(Renderer);

for(var joint:Renderer in BodyVisual){

joint.active = false ;

}

For some reason, this makes everything in my object with the script inactive. I want to select an object as a parent.. What should I do?

Ps: sorry, I don't know how to put the "code" format in when I'm commenting.

avatar image Rush3fan · Jan 27, 2012 at 05:56 AM 0
Share

Also, this has nothing to do with joints of course..

avatar image Lo0NuhtiK · Jan 27, 2012 at 06:06 AM 0
Share

Ok.. so, you're wanting to disable the renderer "ONLY in the object this script is attached to" and NOT in the children?? Or what? I'm confused now. You wanted hingejoints, and are accessing children, but you really want a renderer and the parent?

avatar image Rush3fan · Jan 27, 2012 at 06:17 AM 0
Share

In this line: var BodyVisual:Component[];

I want to select just the car body mesh (which has many roots) with the inspector and hide the car body mesh. If I disable everything inside the car that the script is attached to, then you are disabling some imortant things besides along with the car body, wich is not what I want. I hope that make more sense..

avatar image Lo0NuhtiK · Jan 27, 2012 at 07:39 AM 1
Share

Why do you have them all stacked crazy like that? Is there a method in the madness? ... If not, you could make all those things "children" of Body_Visual, and hit'em all at once. I don't know how to go through 500 generations of objects in one shot, and don't feel like figuring it out at the moment either lol

To get them in one shot After making them children, not great^infinityGrandChildren objects , you could simply do this ->

var bodyVisual : Transform ; //drag it on here   //then do whatever you're doing to call the renderer-disable stuff and for(var child : Transform in bodyVisual){ child.renderer.enabled = false ; //disable children renderers } bodyVisual.renderer.enabled = false ; //disable bodyVisual renderer

and be done with it.

EDIT :

NOTE : That image and the info that you're wanting to disable the renderers should have been what you originally posted in your question, not stuff about disabling springs in hingejoints and InvalidCast errors.
Show more comments
avatar image
0

Answer by Smorgon Magma · Apr 08, 2014 at 04:35 AM

It may sound too simple but just park the object off screen. Choose a position that's behind the camera and miles away. Make sure that you save the location before moving it then reload the position when you want the object back.

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How do I mount a Vehicle? 4 Answers

enable/disable child objects? 2 Answers

Enable/Disable children / group of objects 0 Answers

Cs question from js user, how to get all children? 1 Answer

Disable any objects through 1 script 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