- Home /
Destroying GameObjects instantly when quitting
Hey folks!
I'm working on a project that can cause a loooot of gameobjects to be created. This is perfectly fine until it comes time to close the program, at which point it can hang for upwards of a minute or two while it tries to clear all objects from the scene.
Is there a way to just instantly destroy everything in the same manner that Windows' 'End Task' does to ensure a speedy application close?
When you say a lot how much is a lot? Do you have code in those objects destructors/OnDestroy $$anonymous$$ethods?
Can be in the thousands. There's some code in OnDestroy, but nothing major.
Answer by Nk_Khumbhani · Feb 03, 2020 at 12:17 PM
Destroy game object when no longer use or use:-
void OnDestroy() { Debug.Log("OnDestroy"); }
In this method destroy your game objects mannually
Not what I'm after I'm afraid. Destroying objects isn't the problem, it's the time taken to remove them all when quitting the application
Answer by joker_yash96 · Feb 03, 2020 at 12:32 PM
Try using object pooling that will help you. If you have repeating objects.
Btw why are you trying to destroy the objects when Game Quits?
Answer by haseeb5639 · Feb 04, 2020 at 05:23 AM
It would be automatically destroyed when you'll quit the game. Or Give all objects the same tag. And paste this code in your Quit Function
Destroy(GameObject.FindGameObjectWithTag("Your Tag Name"));
The problem isn't that I need to destroy all objects. It's that all the objects automatically being destroyed when Unity quits cause the software to hang.
Trying to see if there's a way to have them all be destroyed instantly and essentially force closing the software ins$$anonymous$$d of having to wait for them all to be destroyed
Answer by ShadyProductions · Feb 04, 2020 at 12:04 PM
The problem isn't in destroying the objects, it's in the way you use your objects and what you do with them that is slowing down the game when it tries to close. You should find a way to reduce your total amount of objects in your game. Perhaps if you can show what your objects are we can provide examples on how to improve the use of your object usage.
It's a map creation tool for tabletop games, so there's no way to reduce the number of objects.