- Home /
Draw call reduction for a stream of bullets
I'm noticing that when I hold down the fire key, my rapid fire machine gun causes the draw calls to go from 12 to 94. Each bullet is an instantiated prefab right now with a Projectile
script on it that handle collision behavior, hold damage variables, etc.
Ideally, since I'm cloning a prefab with an identical material, my draw calls should go from 12 to 13 when I hold the fire button.
Should I create a global ParticleEmitter
for each projectile type that compiles it all in single draw call for me? That seems crazy and I would love the ability to still tweak game values on individual projectiles if I need to.
Answer by Eric5h5 · Apr 27, 2010 at 04:23 AM
Every individual object is at least one draw call whether it shares a material or not. (Except on Unity iPhone, with some restrictions, but even that has overhead compared to one real draw call to begin with.) Generally speaking, for a rapid-fire gun, you wouldn't really generate hundreds of individual objects, because that's a lot of resources to devote to something you don't even see in a lot of detail. Instead you do a raycast or similar, and make an effect that simulates lots of bullets, such as (indeed) a particle system.
This is nor really true. If your objects share material (and with some more restrictions: http://docs.unity3d.com/Documentation/$$anonymous$$anual/DrawCallBatching.html) they should all go in a single draw call. Though the physics on a whole lot of bullets is very heavy, so doing a raycast is still a better idea.
It was true in 2010, when I answered.... Actually it's still true that making lots of separate bullets is not the best idea, even with dynamic batching (which still has overhead, and sometimes doesn't result in any real performance gain anyway).
It's true it's not a good idea, the raycast is the better idea, though in my experience dynamic batching gives a considerable performance gain (with thousands of objects, running at 60fps and 30 on ios (ios is capped at 30))
iOS isn't capped at 30; you can use Application.targetFrameRate = 60 (which it is capped at, since the screen has a 60Hz refresh rate with vsync forced on).
Weird, then why does xcode shows maximum of 30fps? (in any project, even when there's nothing)
Your answer
Follow this Question
Related Questions
Is there anyway to get Unity GUI to cache an image? 1 Answer
Beast lightmapping and draw calls 1 Answer
How does the iPhone handle draw calls? 1 Answer
Dynamic Batching, Combine Meshes? 1 Answer