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
8
Question by noflyzone · Aug 26, 2010 at 02:46 PM · destroyactiveenabled

What is the difference between these three ways of making an object disappear?

gameObject.renderer.enabled=false
gameObject.active=false
GameObject.Destroy(gameObject)


These three are each make the object disappear from the scene. What is the difference between them?

EDIT: for clarity

Comment
Add comment · Show 1
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 Fattie · Mar 19, 2015 at 08:29 AM 0
Share

Note carefully ...

http://answers.unity3d.com/questions/458780/if-you-disable-a-gameobject-does-an-invokerepeatin.html#answer-458797

3 Replies

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

Answer by Daniel-Brauer · Aug 26, 2010 at 04:11 PM

For InvokeRepeating...

1) disable whole game object - InvokeRepeating does NOT stop

2) disable just the script component - InvokeRepeating does NOT stop

For coroutines...

3) disable whole game object - coroutine >>> DOES <<< stop

4) disable just the script component - coroutine does NOT stop

In all four cases, the repeat is "eliminated", it is NOT paused. If you again SetActive(true), in all four cases, the repeat does NOT continue where it left off.

Simply use OnDisble() and the similar routines if you want custom behaviour on disabling.


Behaviour.enabled and Renderer.enabled stop an attached Renderer or Behaviour (MonoBehaviour and number of other components) from running their update code. In the case of Renderers, it stops them from showing. You can turn this variable on and off from code or use the checkbox next to the Behaviour in the Inspector. Note that not all Components are Behaviours or Renderers, so (for instance) Colliders can't be disabled.

GameObject.active is like enabled, but for all Components on a GameObject. Instead of just stopping Update() and rendering callbacks, it stops all callbacks and coroutines. GameObject.active is the only way to turn off attached Colliders. You can turn this variable on and off from code or by using the checkbox at the top of the GameObject inspector.

Object.Destroy() causes the permanent deletion of its target. This can be a Behaviour, Component, GameObject, or anything else that inherits from Object. If you destroy a GameObject, all of its attached Components will also be destroyed. Destroy() is the same as selecting something in the Hierarchy and deleting it. Destroy() is irreversible.

Comment
Add comment · Show 4 · 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 synapsemassage · Mar 29, 2011 at 08:16 PM 0
Share

In this context, it would be cool if daniel could also tell the difference on gameObject.SetActiveRecursively(true/false); :-)

avatar image Daniel-Brauer · Mar 30, 2011 at 05:05 PM 0
Share

That's just a way of setting GameObject.active on a hierarchy of objects. It doesn't have any special behaviour or side-effects.

avatar image jkgd · Jan 24, 2013 at 04:18 AM 0
Share

Do coroutines still run if Component.enabled == false?

avatar image Fattie · Mar 19, 2015 at 08:32 AM 0
Share

hi jkgd .. see the exact answer in the bold lines added to the answer.

avatar image
1

Answer by AliAzin · Aug 26, 2010 at 04:03 PM

GameObject.Destroy(gameObject) delete the game object, gameObject.active=false disable the game object and all of its components, gameObject.renderer.enabled=false disable only the renderer so you can't see the object but all of its components do work.

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 sigs · Feb 17, 2012 at 06:47 AM

it would be nice to know more specifically what changing Renderer.enabled does. For some reason, toggling GameObject.enabled back and forth can take a LOT of time; no very good explanation is given in the docs where the time is wasted at.

For instance, what kind of CPU/GPU traffic should I expect from toggling Renderer.enabled? Will VBOs be re-uploaded every time? Are collisions enabled when renderer is disabled? What about skinning calculations?

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 Fattie · Mar 19, 2015 at 08:28 AM 1
Share

it couldn't be simpler - if you disable the renderer, that disables the renderer! the renderer DRAWS THE OBJECT ON THE SCREEN. it's that simple. everything else (scripts, colliders, physics, UI, whatever - anything at all you have on the game object - of course keeps running. it's just that it is "invisible".

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Button to create object??? 1 Answer

How To Keep GameObjects From Enabling Again? 2 Answers

Active Prefabs 1 Answer

Why does script continue executing when turned off or destroyed? 2 Answers

Destroy and instantiate far objects 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