• 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
11
Question by nntvog · Nov 14, 2009 at 07:22 PM · gameobjectvisibility

How to make an gameObject invisible and disappeared

I have 2 questions:

  1. How to make an gameObject invisible but I can still interact with it.
  2. How to make an gameObject disappeared and reappeared without destroying and creating a new 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

8 Replies

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

Answer by $$anonymous$$ · Nov 14, 2009 at 08:41 PM

You can turn off the rendering of a GameObject by disabling its MeshRenderer component, e.g.

GetComponent(MeshRenderer).enabled = false;

You can disable a GameObject entirely by making it inactive, e.g.

gameObject.active = false;

Comment
Add comment · Show 8 · 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 tensus2000 · Oct 14, 2011 at 05:03 PM 0
Share

where does this text go and what do i attach it to? i just get error if i put it into the update and attach it to an object.

avatar image Cyber_Defect · Nov 14, 2012 at 01:13 AM 0
Share

you cannot use adjust a property on an uninstantiated object (e.g. a function call)

GetComponent("RPGCamera").enabled = true;

I would go into your RPGCamera script and generate some setters and getters.

then you could say: if (Input.Get$$anonymous$$eyUp ($$anonymous$$eyCode.F)){ $$anonymous$$ainCamera.setEnabled = false; RPGCamera.setEnabled = true; }

avatar image Lost_C4 · Jan 05, 2013 at 06:59 PM 0
Share

@tensus2000 It is important that you use Unity 3. If you use Unity 4 you should use this script http://docs.unity3d.com/Documentation/ScriptReference/GameObject.SetActive.html

avatar image Cyber_Defect · Mar 22, 2013 at 12:38 AM 0
Share

ok, apparently you can... odd.

avatar image psantoki · Apr 23, 2013 at 02:22 AM 1
Share

Hi technicat! Two small additions to these good answers

  1. "gameObject.active = false" does not stop the object from rendering.

  2. "gameObject.renderer.enabled = false" only works if you have one renderer on your object, at the top level. If you have a complex model with lots of parts and a hierarchy then one must hunt them all down and disable them all.

Show more comments
avatar image
31

Answer by illustir · Oct 21, 2015 at 02:31 PM

Even better than messing with the alpha or the renderer, is this solution which I'm now using without adverse side effects:

 // Hide button
 GameObject.Find ("ShareButton").transform.localScale = new Vector3(0, 0, 0);
 
 // Show button
 GameObject.Find ("ShareButton").transform.localScale = new Vector3(1, 1, 1);
Comment
Add comment · Show 6 · 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 jroto23 · Nov 28, 2015 at 01:01 PM 2
Share

I love you man, this worked after wasting 1 hour with setActive (which I cannot bring back) and moving buttons into layers that I don't render

avatar image rTECH · Mar 21, 2016 at 07:34 PM 1
Share

This is so simple, I didn't even consider it and yet it works like charm. Not to mention that disabling the mesh renderer is a bit tricky when u want a non-mesh parent to disappear with all of its children. Thank you.

avatar image tomerpeledNG · Jan 19, 2018 at 09:03 PM 0
Share

This is great!

However, I have difficulties with this implementation and ScrollRect. When changing the localScale to Vector3.One, the ScrollRect is always at the bottom. Any way to workaorund this? I want it to be at the top. Already tried ScrollRect.verticalNormalizedPosition = 1 with no success...

avatar image tomerpeledNG tomerpeledNG · Jan 19, 2018 at 09:35 PM 0
Share

Actually just figure this out, I'm using new Vector3(0, 1, 0), so that the y won't be hurt and it works!

avatar image biboserge · Nov 26, 2018 at 04:55 AM 0
Share

Your solution is the best. Thank you, man. Setting the meshrenderer true or false affect other gameobject with the same type. (Eg: if you set the capsule's meshrenderer to false all other capsules will be off even if you use tags).

avatar image hotlabs · Sep 16, 2021 at 12:01 PM 0
Share

This should be flagged as the best answer. Simple and effective

avatar image
1

Answer by Mann1ng · Oct 20, 2010 at 11:39 AM

Just to answer your question regarding physics..

renderer.enabled is different to renderer.gameObject.active in that .enabled will continue to consider physics on your invisible object.

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

Answer by pablo · Nov 19, 2009 at 11:32 AM

i have a question, if i set gameObject.active = false; does it stop the engine from making calculations (like physics ones) ?

I am preallocating 10 objects and placing them out of screen, but i don't want them to generate any collision/calculation,etc when i have them in this "not used" state.

Would gameObject.active = false; achieve this?

Thanks

Comment
Add comment · Show 2 · 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 BerggreenDK · Oct 14, 2011 at 05:29 PM 2
Share

@pablo I think you should copy this question into a new question as you should only reply to the first question if you have the answer or a comment. Hope you will understand.

avatar image lavapig · Mar 22, 2015 at 04:13 AM 0
Share

now its .enabled, but it will not do any calculations... no.

avatar image
0

Answer by E2R_Ben · May 17, 2012 at 02:33 PM

I am trying to call this function with my current script but it is not working.

The game is third person, however this script is used to move the camera to first person view (to look at something closely for example) when the "F" key is depressed.

However the character mesh gets in the way so id like to turn it off using the above function, but it does not work. What am I doing wrong?

    var FPSLocation = GameObject.Find("Player/FirstPersonLocation");
 
 function Update (){
 
 
 if (Input.GetKey (KeyCode.F)){
 
 
 GetComponent("RPGCamera").enabled = false;
 
 GameObject.Find("CameraHolder/Camera");
 transform.position = FPSLocation.transform.position;
 
 GetComponent("Player/3rd Person Controller").enabled = false;
 
 
 
 }
 
 if (Input.GetKeyUp (KeyCode.F)){
 
 
 GetComponent("RPGCamera").enabled = true;
 GetComponent("Player/3rd Person Controller").enabled = true;
 
 }
 }
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
  • 1
  • 2
  • ›

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

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

Related Questions

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Zoom In: Reveal hidden object - help 3 Answers

Show and Hide a prefab or GameObject 10 Answers

Instantiate as child 3 Answers

How do I stop an immediate collision with all objects from ocuring at the entry of game mode? 0 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