- Home /
Dynamic Batching Not Working
I have a scene with 5 enemies and my main player. The 5 enemies have the same material, way under 300 vertices/tris each, but are not being batched. I created a test scene that only had the 5 enemies in the scene, nothing else, and they do get batched. I removed all code that moves/rotates the enemies thinking maybe that was creating a new instance of the material, but that did not help. What am I missing?
Also, My scene stats say that 5 objects are being batched when the 5 enemies are just off the left edge of the scene view. I also tested this by moving 2 of the enemies further to the right, then moving my player so that those 2 were just off the left edge of the screen. Now the stat window says 2 objects are being batched! Is dynamic batching related to the camera position? and why aren't they being batched when they are in view?
Answer by chris 5 · Dec 21, 2010 at 06:15 PM
Figured this out: When I do my sprite animations I was modifying the enemies' renderer.material. This creates a new instance of the material, thus breaking the batching. I changed it to renderer.sharedMaterial and they batched! The only problem is that now all of the enemies have the same animation. However I think I can make this work for my game.
You shouldn't be forced to have every sprite be playing the exact same frame. Are you changing the material each frame of the animation?
is there a way to shift the offset of an objects texture without causing another draw call? i thought if they all shared the same material, and texture atlas, that the entire texture would be batched, and you'd be free to move around it to update the objects texture? is this not the case? currently, i have 120 cubes all with 16 possible offsets set using, // thisTransform.renderer.material.SetTextureOffset ("_$$anonymous$$ainTex", Vector2(.75, 0));//example of one of the 16 offset possibilities. //and I get one draw call for each cube, even if it's at the same offset! you'd think they'd share.