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 WilliamFerdinand · Jun 11, 2015 at 05:28 AM · physicsdestroy

How do I enable an object when it is destroyed?

Hi, I am trying to enable an object when it has been destroyed previously. What I am trying to do it turn off a script temporarily and then be turned on again after the player presses a key. Is there another script to disable and enable scripts. I searched through the API and the tutorials and couldn't find anything. I have tried using "SetActive" but that only works for gameobjects. Thank you in advance.

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 abi-kr01 · Jun 11, 2015 at 05:53 AM 0
Share

say i have a gameobject(player, with script xyz ) and from other gameobject (main, with script Abc) i want to enable/Disable the player script .then i would do player.xyz.enabled=false;

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Duskp · Jun 11, 2015 at 09:14 AM

You can enable or disable Behaviours be setting the "enabled" bool.

In your case, for example, running the code on the ABC script:

 player.getComponent<xyz>().enabled=false; // disable the script running on the player
 gameObject.getComponent<abc>.enabled=false; //disable the abc script

You might want to simply use gameObject.Destroy() if you're not using the object for anything else, though.

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 Kiwasi · Jun 11, 2015 at 08:14 AM

Destroyed means it's gone forever. No take backs. You can set enabled to false instead. Or you can use AddComponent to recreate the component.

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 fafase · Jun 11, 2015 at 08:27 AM 0
Share

This is not entirely true. I had a student once who thought it was a good idea to use WeakReference to revive destroyed objects and it worked. It was wrong but working.

Destroy does not remove from memory, it sets as useless and remove all references. If you call the GC right after then yes, most likely gone. But if you let it happen as you should, the item will stay in memory until space is needed and GC is called by compiler. During that time, you can zombiefy your object making it alive 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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Is there a way to destroy an object besides Object.Destroy? 1 Answer

onTriggerEnter issue? This should work! 1 Answer

Removing A Component From An Instantiated Prefab After X More Are Instantiated 1 Answer

How do I kill/disable something during a Physics iteration? 1 Answer

Destroy Mesh Renderer under physics possible? 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