Making an iOS game.
Being relatively new to development and Unity (since September), I recently (1 month ago) discovered that instantiating and destroying game objects (with mesh renderer, collider and rigid body components) every 4 seconds in my game killed it’s performance (basically due to the garbage collection us I understand). So I ended up using another method to do what I wanted (make collectibles appear in random places every 4 seconds) and it works perfectly.
On implementing a specific new feature yesterday, I used instantiate and destroy on game objects that are comprised only of a rigid body and a box collider components. The objects are created more seldom (every say 8-10’') and are destroyed when I collect a bomb that destroys all of them that are in screen (about 30 objects of this type at a time).
What surprised me (cos basically I was experimenting) there is no noticeable performance hit, even though I use instantiate and destroy. Does the fact that the game objects don’t contain a mesh renderer play the basic role in this? I am thinking that maybe the game plays ok but it consumes much more battery power so it still is short of a problem. I ran the profiler with 2 versions of the game (the one with and the other without the colliders’ instantiations and destructions) and there was no difference in the stats, except from a momentary great increase of the frame time to 250, that could be caused also from the explosion effects and the audio clip that each destroyed game object plays.
So, does instantiating and destroying game objects with just a box collider and a rigid body, not impose a serious overhead?
The mesh renderer certainly would increase the memory and rendering overhead of your game. Did your original objects also use mesh colliders rather than box colliders? Mesh colliders have a much higher overhead, so they might also tend to slow your game down if you were instantiating a lot of them.
Thanks andeeee, no there are no mesh colliders, only box colliders. I read again my original post and I hope It’s not confusing: what happens now is that I have only box colliders in the instantiated objects and the game runs pretty smooth. On the other hand, in another case last month, when trying to instantiate gameObjects with mesh renderer + box collider (+rigid body) I had a serious performance issue. Just wanted to make sure that the performance difference between the 2 cases is caused probably by the absence of mesh renderer in the 1st case. ![]()