No batched draw calls (when I think there ought to be)

Hi there,

I’m pretty sure I must have some fundamental misunderstanding of batching because this feels like a dumb mistake to me, but your help would be appreciated…

I’ve got a simple scene where I’m drawing hundreds of instances of the same prefab. The prefab has two plane meshes that both use the same material. When I look at the profiler, I get two draw calls per instance of the prefab (one for each plane mesh). Based on what I’ve read on the forum and in the Unity documentation, I feel like these should all automatically be batched into one draw call since its the same mesh and same material. Is there something I’m not getting here?

Thanks.

if the polycount of it is more than 300 vertices it won’t do dynamic batching, the shader needs to be having one pass of what i have seen so with the diffuse shader it will batch, bumpdifusse maybe but once poly count is over then it won’t batch. now if they are set to static it will be using static batching which is of a more higher polycount and the shader doesn’t seems to matter. i bumped into a situation like this. i’m using the 3.5b version so i haven’t yet seen the batching situation there as of yet since i haven’ tested it out there so the info i gave you was from when i was using unity 3.4.2. i think you can’t do static batching unless you are using pro or the other way around?

diffuse bump will batch too but it will not end on 1 drawcall cause bump means pixellight and every single mesh hit by a pixellight will be redrawn on its own again for the light itself.

the mesh is an extremely simple (4 verts, 2 triangles) plane mesh I imported from Blender. I also tried it with the built in Unity plane mesh. I’ve tried it with a few different materials… ultimately I’d like it to work with the transparent cutout diffuse material, but just to simplify things, I am now just using the basic diffuse material.

So the mesh is definitely simple enough. Its moves so its not appropriate to use the static batching toggle. Any other things that could be causing a problem?

Is it rigged/skinned mesh? If so: Skinned/Rigged meshes don’t batch, no matter if they have less than x polys or same material. Only non-rigged/-skinned meshes can be batched

Nope… not skinned, though I’d like to see some creatively skinned/rigged 2-triangle plane meshes.

Its just a really simple prefab. It should automatically batch draw, right?

Say you made a prefab with just a plane old unity cube mesh and one shared material and then you dragged 10 instances of it in your scene. Theoretically it should just be drawn with one batched draw without any additional work, right? Or am I fundamentally missing something?

The default cube does batch. That is if you have it enabled of course. Player Settings > Other Settings > Dynamic Batching checked on :wink:

Well, you didn’t said what the 2 planes do. If you just add a single bone, it’s already considered as “skinned/rigged” model and Unity will attach a “Skined Mesh Renderer” Script to it instead of a “Mesh Renderer”

hmmm… i made an example scene with that simple cube prefab and the batching worked like I expected. I guess I’ll rebuild my other scene over again and keep track of where things start to go awry.

what is build target? it could affect the result.

ok… I started rebuilding my original prefab which wasn’t batching correctly and I came to a step where it screws it up.

Like I said before, the prefab has 2 plane meshes. They basically share the same position and there are two so that it gets drawn from either side. The texture map on it isn’t symmetrical so to make sure it draws correctly, I flip the second plane by setting the x scale on its transform to -1.

This is where the batching breaks. I didn’t a little experimenting and anytime any of the planes scale transforms have any non-one value, it breaks the batching. Based on the documentation that I read, I was under the impression that any dynamically batched objects could have different transforms as long as they are under 300 vertices. Guess I’m gonna need to just find a different approach where I won’t have to reverse-scale the mesh on the x axis.

Eh yea. Only objects with same scale will batch.

But why would you use two meshes on the same position instead of simply drawing the back? Just use a shader which has culling turned off to render it from both sides. Or what are you trying to accomplish exactly?