Dynamic batching draw call problem

Hi,

I’m new (one month) with unity and i’m currently struggling on a problem since some hour now.

I’m trying to optimize a game library by reducing draw calls. After reading the forum i did write a texture packer script to combine my materials and it work great when i use a built-in textured cube object: I can create unlimited textured cube with only 1 draw call.

But if i use an imported model (a tree: one mesh, 59 verts, 54 tris, uv,uv2) then each tree model will sometime use 1 draw call (depending on the camera position it sometime work: 1 draw call for all the model).

I did upload a video to see the problem in action, from what i understand i should only have 3 draw calls in this scene but you can see that it can reach 6 draw calls or more.

I’m really impatient for some explanations :slight_smile:

Many thanks in advance,
David.

Have you double checked everything in the guide?

http://unity3d.com/support/documentation/Manual/iphone-DrawCall-Batching

Trees are good candidates for static batching as well, as I imagine they don’t move in your game. Perhaps mark them as static if this is the case.

Hi! Thanks for the reply.

Yes i did read that article a lot :stuck_out_tongue:
As we can see in the video i do respect the guidelines:

  • No object in the scene is scaled.
  • They all share the same material and packed texture
  • No object is more than 100 verts.

I do also have the same problem with a simple cube model from blender. In fact it work if I only use built in cubes. As soon as I pack a prefab AND use a built in cube in the scene (even a simple cube from blender) draw calls will goes crazy even if they do share the same material.

Static batching is not an options as i do not own unity pro :stuck_out_tongue:

The problem is still actual. Everytime i mix two different object (resulting in 1 or 2 different materials and textures packed with texture packer) the draw calls goes crazy.
I can spawn around 10K verts of the same cube in 1 draw call, either a built in unity cude or a blender made cube.
It seems that we can use a different shader for each of the two model to make the draw call to be as excepted ( 1 draw calls for 500cube1 + 1 draw calls for 500cube2 ) but then it meens we need 1 draw call per model in the scene which is not what is excepted.

Here is again my problem explained which seems to be an unity problem :

  • Rendering path = VertexLit

  • Shader = Any

  • 1 directionnal light or no light

  • Instantiate around 800 built in cube = 1 draw call :

  • Instantiate around 800 blender cube = 1 draw call :

  • Instantiate built in cubes and blender cubes = 187 draw call (either with 2 shared or 1 shared material for all the objects)

  • Instantiate built in cubes and blender cubes with two different shader : 2 draw call

  • Reference screenshot for draw calls count :

potentially your blender cubes contain more than just position, normal and a uv coordinate (like vertex colors etc) which prevent it from properly batching?
Also did you check if the ‘optimize mesh’ in the mesh import settings help?

Also more important: does it happen if you mix it with other blender meshes of similar complexity or only against unity ones

@Capasjuste I hope its ok to post this in your thread but its kind of related I think.

I read about drawcall batching and found in the docs this part:

“Don’t use scale. Objects with scale (1,1,1) and (2,2,2) won’t batch.
Uniformly scaled objects won’t be batched with non-uniformly scaled ones.
Objects with scale (1,1,1) and (1,2,1) won’t be batched. On the other hand (1,2,1) and (1,3,1) will be.”

I dont understand that part.

a scale of (1,1,1) isnt a scale, is it? Why wont this batch?

and this:

(1,1,1) and (1,2,1) won’t be batched… (1,2,1) and (1,3,1) will be.

Thank you for helping.

First, many thanks for the advices. With your help my main problem seems now to be identified :

  • The draw call problem occur when i use two different mesh with different property eg. : position, normal, uv, uv2, color etc. The built in cube mesh is “uv, uv2, colors” while my Blender cube is “uv, uv2”.

- Since i don’t know how to add a “colors” attribute to my blender mesh, i did build another blender cube (with different uv texture mapping) but with the same attributes as the other blender mesh (“uv, uv2”) and now all work as excepted. I can batch the 2 mesh in one draw call..

I’m doing more test actually and report back but i’m very happy, thanks for the hint :smile: