- Home /
Efficient way of having 1 draw call but allowing for debris physics [Mobile]
I'm making a tower defense game and I'm just going around doing some random optimization.
I noticed a hand full of my vehicle enemies have anywhere from 3-10 draw calls which is unacceptable for mobile development. I can easily combine the mesh into one, this isn't a problem. Where my issue is, is I add force/torque to a hand full of the objects per vehicle for when they "die" so that they explode. This adds a really beautiful and random explosion. Looks awesome and I don't want to take this away.
So I can't have this 1 draw call because of the debris, but at the same time 10 draw calls is outrageous.
I can think of a few work arounds. For example I can combine any meshes I'm not using for physics. This isn't horrible but isn't the best (will still leave me with more then 1 draw call). I also can combine the mesh for displaying the enemy when it's alive and then when the enemy dies I can spawn a prefab of a dying effect that isn't 1 mesh. This way I'm not ALWAYS showing ~10 draw calls per enemy, only when it's dying.
I'm asking this question basically looking for advice. There has to be an efficient way of doing this while still keeping your game beautiful.
Thanks.
Answer by Jamora · Sep 04, 2013 at 06:43 AM
Random optimizations aren't very rewarding in their time spent/performance gained ratio. You should really use the Unity profiler (or any profiler) to identify the bottlenecks and work on those. Changing random parts of the code that 'look' like they could cause lag could, in the worst case actually cause more lag.
Here's Unity's Practical Guide to Optimizing Mobiles; an interesting read.
One way I know of getting one draw call for your debris is by using the same material on each mesh. If they have different textures, you should create a texture atlas of the textures. (The other way is using CombineMeshes, but that doesn't work for you in this case.)