Someone in the Unity forums asked me how Zombox maintains performance even with all the active colliders and rigidbodies within the environment. I figured it would be a good time to explain some of what goes on behind the scenes in the Zombox engine.
The game uses a fairly complex pooling system I wrote to create the environment.
Firstly, because everything in the game procedurally generated from a small set of prefabs, I can easily enable/disable anything that is not directly within the view frustum. Not just disable its renderer…but literally remove it completely, and use its gameobject to create something that *is* in screenspace. This means the total number of active rigidbody/static colliders in the game is limited to what’s visible in screen space, because only a finite set of gameobjects are used to create everything. The entire city features over 350 buildings (each with many walls, props, etc….about 40,000 different “pieces” are required to create the whole city), many roads, rivers, etc…but all of that is generated using only 300 gameobjects, which are recycled constantly. This keeps the game running really fast and there are no load times in the huge sprawling environment once the initial city-generation load time is passed (and that initial load time only takes a few seconds).
Secondly, the pooling system also manages the number of active non-kinematic rigidbodies, so that I can easily control the max number of rigidbodies in the game at any time. The downside is that the same small group of rigidbodies are recycled for new zombie/building/environment chunks that are generated, so as new chunks pop in (like when a wall is crumbled, or a zombie is killed), old chunks pop out. But generally this effect isn’t that noticeable and doesn’t detract from the gameplay.
I think I’ve got about 30 rigidbodies in the building-debris-rigidbody pooling system, a dozen in the zombie-limb pooling system and a few more in the environment-debris pooling system. With all of those rigidbodies active and colliding, the game runs at about 20-30 fps on the iPhone 3GS, and 30+ fps on the iPhone 4.
The following gif showing the environment pooling system in action. The white lines represent zombie paths, and the roofs are disabled so you can easily see all the objects necessary to build all the walls of each building.