x


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.

more ▼

asked Apr 27 '10 at 02:45 AM

Squeegy gravatar image

Squeegy
235 8 10 21

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Apr 27 '10 at 04:23 AM

Eric5h5 gravatar image

Eric5h5
80.3k 42 132 521

This is nor really true. If your objects share material (and with some more restrictions: http://docs.unity3d.com/Documentation/Manual/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.

Jan 03 at 12:15 PM The Oddler

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).

Jan 03 at 03:30 PM Eric5h5

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))

Jan 03 at 05:41 PM The Oddler

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).

Jan 03 at 06:21 PM Eric5h5

Weird, then why does xcode shows maximum of 30fps? (in any project, even when there's nothing)

Jan 03 at 06:29 PM The Oddler
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x664
x644
x110
x69

asked: Apr 27 '10 at 02:45 AM

Seen: 1949 times

Last Updated: Jan 03 at 07:29 PM