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
1
Question by AlexFili · Sep 22, 2012 at 03:06 PM · invisiblereappear

How to make an object invisible

I've been trying to use the following code to make objects invisible:

renderer.enabled = false;

However it doesn't make any difference and is still visible in the scene. I need it working so that if the players objective is 0, the objective is invisible but if the player's objective is 1 or higher, the object becomes visible again.

![alt text][1] [1]: http://25.media.tumblr.com/tumblr_marg19JK751qjvatjo1_500.png

What I want is to make the chain of the mug disappear until the first objective is complete, but at the moment the code isn't working. Could someone make an example Unity project of like a disappearing cube?

Most of my project is using Javascript. Not sure if this is what's causing all the problem or if it's something else.

Problem solved. Thanks for the help everyone :)

Comment
Add comment · Show 10
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 whydoidoit · Sep 22, 2012 at 03:07 PM 2
Share

I'm guessing that your script is disabling the wrong renderer - because disabling a renderer will make an item invisible!

avatar image MithosAnnar · Sep 22, 2012 at 03:13 PM 0
Share

Hey $$anonymous$$Fili,

That code works perfectly for me. Could you send me the test project via www.wetransfer.co.uk ?

$$anonymous$$y email is $$anonymous$$ithosAnnar(at)gmail.com.

I will look at your project and tell you what your'e doing wrong there.

Cheers!

$$anonymous$$ithos

P.S. Don't forget to zip it before you upload it!

avatar image whydoidoit · Sep 22, 2012 at 03:15 PM 1
Share

Can we please try to keep discussions on Unity Answers - this is a knowledge base and is useful for searchers in the future - if you take a discussion to email the result and the process of finding it will be lost.

avatar image MithosAnnar · Sep 22, 2012 at 03:19 PM 0
Share

Hi Whydoidoit,

The idea is that I download it and post the answer on how to solve the issue here on unity answers as detailed as I can.

The email, is just so he can send it directly to me.

Cheers!

$$anonymous$$ithos

avatar image MithosAnnar · Sep 22, 2012 at 03:27 PM 0
Share

$$anonymous$$Fili,

Btw,

If you don't want to send me the project, then 2 renderers on an object can also be the problem.

Something that will always work is:

gameObject.active = false;

You can't get more invisible than that.

Cheers!

$$anonymous$$ithos

Show more comments

3 Replies

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

Answer by MithosAnnar · Sep 22, 2012 at 05:33 PM

Hi Alex,

I made an example scene for you:

https://dl.dropbox.com/u/107533178/DissapearingCubeExample.zip

There is a script on the camera that accesses the cubes renderer. Really basic stuff.

Cheers!

Mithos

Comment
Add comment · Show 7 · 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 AlexFili · Sep 22, 2012 at 05:44 PM 0
Share

Thank you. Looks like I need to go back to basics and try the simple things first!

avatar image MithosAnnar · Sep 22, 2012 at 05:54 PM 0
Share

Your'e Welcome!

Did it work well for you?

If it did I m glad!

Cheers!

$$anonymous$$ithos

avatar image AlexFili · Sep 22, 2012 at 06:19 PM 0
Share

Yep the example you provided did work. Just wondering, is it sensible to mix C code and Javascript code in the same Unity project? Since most of my code is in Javascript. Not sure if that's why I had those problems before.

avatar image whydoidoit · Sep 22, 2012 at 06:31 PM 0
Share

Don't mix them - due to compilation order you will always be running into problems. If you get scripts from elsewhere that are in C# put them in a Plugins or a standard Assets folder so you can access them, with your own code it is harder because there are likely to be two way dependencies and that is not possible.

avatar image whydoidoit · Sep 22, 2012 at 06:33 PM 0
Share

@mithos can you paste the code here rather than a Dropbox link that may one day break rendering your answer useless to future browsers? Thx!

Show more comments
avatar image
0

Answer by SergeantBiscuits · Sep 22, 2012 at 03:34 PM

I'm going to assume you made the same mistake I did when I first started using Unity; you have a GameObject with a bunch of children inside of it. You need to disable the renderers of all the children!

Here's an example script that will make the object visible or invisible depending on whether or not "isVisible" is true:

 var isVisible : boolean = true;
 
 function Update(){
     
     if(isVisible){
         var allMyRenderers = GetComponentsInChildren(Renderer);
         for (var renderer : Renderer in allMyRenderers) {
             renderer.enabled = false;
         }
     }
      else{
         var allMyRenderers = GetComponentsInChildren(Renderer);
         for (var renderer : Renderer in allMyRenderers) {
             renderer.enabled = true;
         }
     }
 
 }

This will loop through all of the object's renderers and disable 'em. To make them visible again, use the same code but with 'true!'

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 AlexFili · Sep 22, 2012 at 03:42 PM 0
Share

Still struggling. Now it's saying: $$anonymous$$issingComponentException: There is no 'Renderer' attached to the 'Chained$$anonymous$$ug' game objectm but a script is trying to access it. You probably need to add a Renderer to the game object "Chained$$anonymous$$ug". Or your script needs to check if the component is attached before using it.

This doesn't make sense to me, if it's not got a renderer component then why I can see it on the game? :s

avatar image AlexFili · Sep 22, 2012 at 03:46 PM 0
Share

Also getting this error: ArgumentException: You are not allowed to call get_gameObject when declaring a variable. $$anonymous$$ove it to the line after without a variable declaration.

avatar image SergeantBiscuits · Sep 22, 2012 at 04:03 PM 0
Share

$$anonymous$$ake sure the code I supplied goes somewhere in the Update() function, including the var declaration. I updated my answer.

avatar image aldonaletto · Sep 22, 2012 at 04:17 PM 1
Share

It's better to avoid a variable called renderer, since this name is used in the GameObject.renderer property. Give another name to the variable, like render. Another point: you can simply assign isVisible to the property ins$$anonymous$$d of using if:

var isVisible : boolean = true;

function Update(){

 var all$$anonymous$$yRenderers = GetComponentsInChildren(Renderer);
 for (var render : Renderer in all$$anonymous$$yRenderers) {
    render.enabled = isVisible;
 }

}

avatar image AlexFili · Sep 22, 2012 at 04:50 PM 0
Share

Could someone make an example Unity project of like a disappearing cube?

avatar image
0

Answer by udaanparvaz · Sep 23, 2012 at 02:41 PM

You can always set the local scale of the gameobject to 0 if memory is not the problem.... gameObject.transform.localScale = Vector3(0,0,0);

Comment
Add comment · Show 1 · 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 AlexFili · Sep 24, 2012 at 07:51 AM 0
Share

Thanks! This works great as a quick fix. Would probably cause some problems with collisions and things like that... but it works really well :D

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

14 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

Related Questions

A node in a childnode? 1 Answer

Imported models partially disappear 0 Answers

Blender 2.62 FBX not importing 2 Answers

Renderer on object disabled after level reload 1 Answer

Part of a model is visible while the rest is invisible. Glitch? 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