In my game there are a lot of objects that can be destroyed when you shoot them.
In spirit with the season i made a version with the text "Seasons greetings" all made out of destructible prefabs. The frame rate doesn't get a hit, but when i destroy a couple there is a frame drop for an instant.
Is there some kind of limit to the number of unique objects i have in a scene?
Thanks a lot! And best wishes!
This is the code on my prefabs:
var object : GameObject;
var explosionSphere : GameObject;
var objectTrigger : GameObject;
var destroyPS : Transform;
var objectLife = 5;
var explosive = false;
function OnTriggerEnter (objectTrigger : Collider)
// Only react on bullets
if (objectTrigger.tag == "Bullet")
objectLife -= 30;
if (objectLife < 0)
if(explosive == true)
Instantiate(explosionSphere, transform.position, transform.rotation);
Instantiate(destroyPS, transform.position, transform.rotation);
GuiScript.Points += 10;
Instantiating many objects in a short time lapse can result in a loss of performance. When possible, you should try to recycle objects rather than creating new ones.
I had a similar problem in my game, where I used to instantiate particle systems to simulate explosions and hit effects. I resolved it by creating a pool of explosions at loading, which is implemented by a circular list. When I need to create a new explosion, I search for the next explosion in the list, position it where I need and enable its particle emitter . When I need to "destroy" an explosion, I just disable it.
This principle can be applied for most dynamic game object, like shoots, enemies, hit effects and so on. Depending on the type of game you are making, recycling objects can result in a huge improvement on fps.
Of course, in order to recycle objects, you need to know the maximum number of objects of a given type which may be active at the same time, and create a pool of at least that number.
there is no object limit. there might be different reasons for FPS drop. first of all you might have heavy rendering with many particles in your explosions. if you use rigidbodies in any of the objects that you create after destruction of this one. they might eat alot of resources. if you have the unity pro you can get more information by using the profiler. as a guideline try to use as lightweight code as possible and keep the number of particles as low as possible. the problem might be a rendering buttle neck or a CPU buttle neck or even a RAM or VRAM buttle neck if you create high polygon meshes with big textures after destroying each object. so there are many possibilities. give more descriptions.