Is there a reason why Destroy() is slower than Instantiating?
I have created 1000 GameObjects. I can create 1000 more with little overhead, but if I destroy those 1000 instead it creates a massive overhead. Putting a staggered delay in the Destroy method justs runs the CPU hot on all 1000 of those scripts until they hit the delay.
I am destroying on the GameObject itself with
Destroy(gameObject);
Does destroy invoke some sort of search a la GameObject.Find?
Is there a way to just destroy the object without Destroy()?
Why the hell is it slower than adding objects?
Answer by MrCrumbl3d · May 24, 2017 at 07:27 AM
Try foreach statement. this can destroy all gameobjects with a tag and destroy all in the same time. no more 1 one by one destroy objects.
GameObject[] object = Gameobject.FindGameObjectsWithTag("tags that located to your objects that you want to destroy");
foreach(GameObject namethiswhateveryouwant in object)
{
GameObject.Destroy(namethiswhateveryouwan);
}
try this code.
Your answer
Follow this Question
Related Questions
How to get the tags of objects if they aren't in the scene? 0 Answers
Check if 2 or more objects of same type is near object. 1 Answer
Can you make script to populate the scene 0 Answers
Collision with trigger is not working 1 Answer
Cannot destroy object when it collides with another object? 1 Answer