Is it possible to stop the destruction of a gameObject after Destroy(SomeGameObject) has been performed? I know that the destruction doesn't actually take place until the Update phase of the Unity thread has been completed, so I was hoping there would be a way to remove my gameobject from whatever destruction queue Unity saves them gameobjects to.
Answer by Benproductions1
Jun 29, 2013 at 03:03 AM
You can't. What you are asking is simply not possible.But you can work around the problem. Plenty of people have already had this problem before you (http://lmgtfy.com?q=unity+cancel+destroy) and there have been plenty of solutions
I would suggest not actually ever destroying it, but rather disabling the object. (This is also faster and more efficient than Destroy)Another method is to use Invoke and CancelInvoke to "cancel" destroying the object (however this can only be used in some cases)
Hope this helps,Benproductions1
I understand the use of disabling object, I was just curious as to whether I could intervene and remove an object from the destruction queue that Unity has.
btw, the lmgtfy link is not appreciated, because this is first thing that comes up when you google gameobject stop destroy.
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
If you are a new user, check out our FAQ for more information.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
For troubleshooting common problems with Unity 5.x Editor (including Win 10).
To help users post good questions and use the site effectively we have posted a user guide. Please check it out.
Answers and Comments
18 People are following this question.
using Contains(gameObject) to find and destroy a gameObject from a list
Destroying a gameobject clone after a time
Problem with destroy gameObject
Problem with object destroy
What happens to GameObjects in a List when Destroy()'d elsewhere?