- Home /
Draw calls not batch for simple cube prefab
OK I have a simple cube that has a simple material applied to it with a custom texture of 64 x 64. And my code looks something like this:
public Transform brick;
void Start () {
for (int i = 1; i < 5; i++) {
for (int j = 0; j < 10; j++) {
Transform temp = (Transform)Instantiate(brick, new Vector3((-2.5f+i),(0),(0.5f+j)), Quaternion.identity);
}
}
}
All I am trying to do is build a simple road, but I need them as single objects so that I can turn off their renderer's dynamically. But the problem I am having is that none of the objects are being dynamically batched and I am producing 72 draw calls. And now I need to duplicate this still at least 3 more times. And the draw calls still don't batch when I use a basic color material, only when I remove the material all together do they finally batch. Been pulling my hair out for days, any help would be greatly appreciated.
O$$anonymous$$ it seems when I change the material's shader to Legacy/Diffuse Fas it starts to batch.....
$$anonymous$$aybe I'm wrong but I think that you can't batch object with two-pass-shader. Also make sure that no script make any change to the material in a "non-shared" way (i.e. using renderer.material ins$$anonymous$$d of renderer.shared$$anonymous$$aterial).
It was set to the regular diffuse shader, so it seems the only shaders that will work on dynamic batching are the Unlit and Vertext Lit?
No Diffuse shader should work (it is a very simple shader). But make sure that all objects do share the same material.
Diffuse was not working unfortunately and the object was instantiated from the same prefab so it should be using the same material I would think.
Answer by Kryptos · Aug 22, 2012 at 09:31 PM
Look at this forum thread: How to get Dynamic Batching to work?
Here is a short summary of what can go wrong (answers by @Dreamora and @Cameron):
you use lightmaps
you don't use uniform scaling (try with no scaling at all aside of the default 1 1 1)
the material is transparent which has impacts on batching
they are not meshes but skinned meshes and have skinned mesh renderers which will not batch at all
same goes for softbody stuff.
same option regarding shadows in all renderers (or no shadow at all is even better)
"cast shadows" looks like to be breaking the dynamic batching, while "receive shadows" should work (don't ask me why, and I didn't test it)
I removed "Cast Shadows". Batch Calls reduced by half!!. Thanks!
Your answer

Follow this Question
Related Questions
How to batch draw calls for instantiated Prefabs 1 Answer
Instantiated UI prefab in canvas does not render image 1 Answer
Prefab not rendering when declaring Transform variable 1 Answer
How to Add Y Axis Offset to transform.localPosition on an Instantiated Prefab? 2 Answers
Referencing gameObject from script after Instantiate 0 Answers