Hello, I am struggling to reduce draw calls in my game. I am following ALL the rules of dynamic batching (no scaling, one texture, material, no where in code am I referring to “renderer”, etc).
But for some reason, my draw count is still way over 100. However, with this snippet of code:
public Material mat;
void Start() {
gameObject.renderer.sharedMaterial = mat;
}
I was able to reduce reduces draw calls. The “mat” variable is the same material, so I am basically setting it self, again?
I don’t understand this… am I doing something wrong here? Please help me understand what is going on.
If anywhere you are using gameObject.renderer.material (not shared) to change things like color or mainTexture, this changes the material, so you essentially create a a new one, then this object wont batch with other, similar objects.
if putting gameObject.renderer.sharedMaterial = mat in a script that applied to all of your objects, all those objects will be using the same material, and can then be batched.
Thanks for your answers and suggestions guys, though I didn’t explain my problem correctly. Apologies… let me try again.
I am creating ~20 objects (by instantiating) at start up. When I create these objects, it is creating a new instance of the material… for some strange reason, and this is what was pulling my hair. It wasn’t referencing the original material (which would help because thats how I could reduce my draw calls). I was not doing any kind of scaling, changing material through code, material/shader is not transparent, etc. It would just create a new instance of my material. My script (as shown above), fixed this. But it was silly having to write it. Oh well.
But I must do what I must. I will just settle with this, thanks for your help again fellas.
Woah! Only 20 objects and your drawcalls are way over 100?! They must be high poly. If they were below 300verts your drawcalls would be as low as 20.
I have 100+ objects in a scene of my game and the drawcalls don’t go above 70. Is the game your making for mobiles or PC? if PC then don’t worry about drawcalls too much man.