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 AtomicMarine · Jan 08, 2011 at 06:56 PM · gameobjectiphonedestroy

Is it Possible to Bring back a Destroyed GameObject?

Lets say I destroy a gameObject in a level (when I kill the enemy)

Is it possible to bring back that same gameObject or a copy of it with the same stats as the original or the original itself (such as re spawning?)

Currently I am trying to make my level reset with only slight differences if the player buys upgrades so for that I need the enemies to respawn is this possible?

should I avoid destroying the game Objects?

Thanks

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

3 Replies

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

Answer by DaveA · Jan 08, 2011 at 07:07 PM

You might try just deactivating it, and/or put it on a different layer (hidden) and/or put it on a 'graveyard' list which would actually be destroyed when you really don't need it.

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 AtomicMarine · Jan 08, 2011 at 08:26 PM 0
Share

Yea I think I'm gonna just move the object to a different off scene location, it seems to be the simplest location since the scene itself isn't using many draw calls and everything seems to render fine either way :) thanks

avatar image
2

Answer by The_r0nin · Jan 08, 2011 at 07:15 PM

Try using Prefabs. You can destroy them and then instantiate exact copies.

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 AtomicMarine · Jan 08, 2011 at 08:25 PM 0
Share

I can't use a prefab because i have many scripts attached to this object but I think I have figured out what I am going to do

avatar image The_r0nin · Jan 08, 2011 at 09:42 PM 0
Share

You do realize that you can put scripts on prefab objects, right? $$anonymous$$y entire player, including the main camera and all of the scripts, is one prefab object...

avatar image DaveA · Jan 10, 2011 at 08:51 PM 0
Share

Instantiating a prefab will bring it in with its defaults. I think he wants to keep all the 'current' variable values at the time of death, and resurrect that (without having to store all that off into another place)

avatar image The_r0nin · Jan 10, 2011 at 09:16 PM 0
Share

Oh... that's not how I read it. That's a completely different solution entirely...

avatar image DaveA · Jan 10, 2011 at 09:33 PM 0
Share

I gotta guess that's what he meant by 'same stats' cuz otherwize, prefab instantiate is the simplest for sure

avatar image
1

Answer by Statement · Jan 08, 2011 at 07:50 PM

Lets say I destroy a gameObject in a level (when I kill the enemy)

Is it possible to bring back that same gameObject or a copy of it with the same stats as the original or the original itself (such as re spawning?)

You can't (as far as I know) "undo" a destroy and have internal state intact without having to write your own code that safe-keeps state. You can probably also kiss coroutines goodbye if you need that explicit control since I don't know of any way to restore coroutine internal state.

I think the best bet is to spawn prefabs and ignore loss of state (per ronins suggestion) or put objects in a graveyard list (per daves suggestion).

Since you're reseting mid-game events I guess you'd want to go with the graveyard idea or write some sort of object state manager, but that can become quite complex and may put serious constraints on the remainder of your architecture.

Comment
Add comment · Show 3 · 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 AtomicMarine · Jan 08, 2011 at 08:22 PM 1
Share

Um it is only one Object, and I technically only need it gone for a short while.

So in retrospect I think I am going to move it to another layer or place out of the scene view and just move it back when the player plays the level again.

avatar image yoyo · Jan 09, 2011 at 04:17 AM 1
Share

Would it be simpler to just set go.active = false, then reactivate it later?

avatar image Statement · Jan 09, 2011 at 01:35 PM 0
Share

I guess it depends on the context but I'd certainly think so.

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

No one has followed this question yet.

Related Questions

using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers

Deleting instantiated prefabs clones? 2 Answers

How to only delete one of two collided objects? 1 Answer

Destroy gameObject not destroying child 1 Answer

game object is not being destroyed 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