- Home /
Why so many SetPass Calls?
I have 40 car objects in the scene all using the same material and texture. Each car model has 4 child wheel mesh models that use the same material and texture. When I have 1 car in the scene it says SetPass calls : 2. When I have 40, draw calls increase to 18. If I deactivate 30 cars then it drops to 8 draw calls for 10 cars. And sometimes it says 10 draw calls for 10 cars. What is going on here? Shouldn't the 40 cars take the same draw call as 1 car? And why do draw calls differ for same amount of cars?! I am missing any basic knowledge here? Any help is appreciated.
Answer by Eno-Khaon · Jan 27, 2016 at 11:03 PM
The SetPass Calls (or draw calls) are performed per object in your scene. It doesn't really matter whether the objects share the same shader or not. Each separate object in your scene requests its own draw call.
But why do you have such a strange count on draw calls?
Dynamic Batching does what it can to be consistent and not batch unnecessary objects together. This isn't always consistent, however. In some cases, objects may be batched in obvious ways and in other cases, they aren't. It's simply Unity doing what it can to decrease the number of draw calls when it seems to be the best opportunity to do so.
One way of seeing exactly when objects are batched together is to make a shader which modifies color (or vertex position) based on the local position of the vertex. Because the object center for batched objects is always the world's zero vector, your color or motion will become very different than expected/intended when the objects are batched together.
That said, this variety in how objects do wind up batching together is why you see variable results. If everything batches together, you'll have two draw calls. Otherwise, 40 of the cars will use up to 80 draw calls.