- Home /
Getting dynamic batching to work with 2D sprites?
Hello, i have been creating a 2D "tower defense" game for Android and i've added a turret that shoots a shell that blows up and creates 4 smaller shells. However, these small shells each create 1 draw call and i end up with about 400+ drawcalls when the player has a bunch of these turrets (and my game normally has around 70), even tho they have the same sprite, material and size and aren't affected by any kind of light (since my game doesn't use any kind of lighting).
I've been looking everywhere to find an answer but haven't found much on dynamic batching with 2D Sprites. Can anyone tell my why aren't my sprites batching even though they are identical to each other? and can also anyone tell me how does dynamic batching even work on Unity 2D?
Also, as another small question, i have a game that normally has about 40 - 70 draw calls for Android too, but it seems to be lagging a lot and the profiler says most of it is caused by the GUI.Repaint, however even when reducing the GUI it still lags. Anyone have an idea what other things could cause the lag?
Thanks for any help, in advance :)
Did you ever figure this out? If not, I have some questions:
Do the 4 little bombs use any sort of animation?
If so, are all the sprites for the animation in the same Graphic file?
Are you recoloring the bombs through code ($$anonymous$$G, renderer.material.color = new Color(colorR, colorG, colorB, alphaA);)
I'm making a defense style game as well, and just noticed that certain objects ARE batching and certain ones are NOT, and the key difference in my case appears to be if they're using graphics from different sprite sheets. Also if they're colored in script, that $$anonymous$$IGHT be breaking one of my objects, but I have more testing to do on that to deter$$anonymous$$e if that's the case.
Answer by raiden · Jul 31, 2015 at 02:21 PM
A few rules to Dynamic Batching I've learned:
Must be enabled in Player Settings
2D Sprites must have the same Packing Tag name
2D Sprites must use the same compression format in the Import Settings
I just ran across this issue in my 2D Game, I had 15 game sprites, these consisted of a sky background and dirt sprites. My top dirt sprites where actually the grass layer, which contained a small corner of alpha, thus giving it a different compression format (RGBA instead of RGB), which was creating the additional draw calls. Once I changed my compression format on the grass sprites to match all the other sprites, "poof" like magic, I reduced my draw calls!
Hope this helps out!
-Raiden
Your answer
Follow this Question
Related Questions
Is it possible to implement Batching directly? 1 Answer
Custom Sprite Renderer - Batching 0 Answers
Unity - Repack sprites at runtime 0 Answers
Is it possible to utilize iphone dynamic batching with "traditional" animated sprite techniques? 1 Answer
How UI Batching works with two different sprites ? 0 Answers