(Solved) Batching sprites in a randomly generated dungeon with Diffuse sprites

Hello,

I am making a 2d rpg dungeon crawler. I have made the content the way I like it and am happy with the way it it is generating the dungeons, applying lighting, placing object and all that jazz. However I am trying to make it run smoothly for webgl. Inside the dungeons in my game fps, according to the stats window, falls from 600 outside the dungeon to ±70 inside the dungeon.

The stats window also shows that I have 10000 batches and I am only saving about 1300 by batching. And so I am getting a ton of drawcalls which I believe is causing the issue.
I have done the following to try and reduce this (numbers in brackets at the end indicate the reference where I got the information):

  • Given all my sprites the same Packing tag (1)
  • Given all my sprites the same Material (1)
  • Given all my sprites the same Compression format in the Import settings (1)
  • Labelled all of my Static objects as Static in the inspector (5)

Here is a picture of my stats window, however sometimes the batches can even reach 12k+

113844-stats.png

The Script that generates the dungeon creates a grid of sprites and then runs through using an algorithm and replaces the sprites with the correct sprite for floor etc, and places 3d objects for walls these are cubes with textures that make them look pixelated. Giving the dungeon a cool mixture of 2d and 3d elements. It should be noted that I have tried to alter the code so as not spawn walls, or not spawn floors, etc.

Im wondering if anyone can Point out some other things that I can try or places that I can look for information on this topic. Sadly I dont have unity Plus to use the profiler. May be getting it later today if I cannot solve this issue without the profiler.

references:

  1. Getting dynamic batching to work with 2D sprites? - Questions & Answers - Unity Discussions

  2. How to see why your draw calls are not batched in 5.6 | Unity Blog

  3. Lower Draw Calls For Sprites - Questions & Answers - Unity Discussions

  4. Unity - Manual: Draw call batching

  5. https://forum.unity.com/threads/draw-calls-for-sprites.249207/

I managed to figure out what the problem was finally while make sure I wrote the question thoroughly. Turns out it was the fact that all my sprites where labelled as diffuse which is fine for batching but when lights are added to the mix every sprites gets a seperate draw call because the lighting influences the sprite and makes it unique.

So the solution is to get creative with how I manage lighting in the game and try to find another way of doing it. Any suggestions to that are appreciated.

References:

https://forum.unity.com/threads/using-sprites-diffuse-material-breaks-batching.254083/