- Home /
Erratic DrawCall batching behavior, I'm going crazy
Hi guys, sorry for the dramatic title but this is absolutely driving me nuts!
I'm making a hex-based 'grand strategy' game for Android. I will have around 300 hex cells on the screen which will be colored based on which country they belong to. (I will add border effects etc. but that's for later)
I have one material which is the diffused hex texture. I use material.color for changing its color.
The way I did it apparently created new material instances for every hex so I ended up with 400 draw calls which is too much.
Then I thought of making just two new materials (one for each country) and applying it to every hexcell that the country owns.
When I do it, create two countries but give the whole map to only one country, voila! It's only 3 drawcalls. (saved 315 by batching)
But when I give some cells to the second country (with the second material) things start getting bad. Every cell I add to the second country adds 2 draw calls.
What's more interesting - the more cells I give to the second country, the draw calls added per cell gets fewer and fewer. At the beginning (as I said) it's 2 draw calls per cell. Then it becomes 2 draw calls per every 2 cells, then 5 cells... and then the total number of draw calls hits a peak (~200) when the map is exactly divided into two countries.
And after that, as I give more cells to the second country, the total number of draw calls actually declines.
Finally, when the second country has taken over the whole map, the number of draw calls has fallen back to 3.
What gives - anyone has any ideas?
edit: Some more info - the objects don't cast or receive shadows, total Tris on the scene: 2.1k, total Verts 2.4k, no scale (all 1)
I don't have a solution to the specific scenario you outline, but I have three alternate ideas that should solve your batching issue:
1) Use a shader that supports Vertex color and change the colors array in the mesh to change color for selection.
2) Use a texture atlas (just two textures for what you have outlined), and change the texture using the uv array in the mesh to indicate selection.
3) Create two hex objects for each cell. One object is for the selected state, one for the normal state. Turn on/off the renderer to change state. Each set of 300 (one set for selected one for normal) shares a material, so all your hexes should draw in two draw calls.
Thank you for listening to my problem and offering some solutions. I'm very thankful. $$anonymous$$y problems though:
Would that not result in there being instances of $$anonymous$$esh ins$$anonymous$$d of a single mesh - essentially the same problem I have now, only with meshes ins$$anonymous$$d of materials? Won't that possibly result in additional draw calls too?
Again the same problem - when I change the UV array in the mesh now I have more than one mesh.
This is actually a great idea but I've thought of it before and the problem is: I plan on having more than 2 countries, also plan to have some effects on the border cells etc. which will all require different cell 'layers' and will multiply the total cell count by 300 each. Won't that be a problem?
Your answer
![](https://koobas.hobune.stream/wayback/20220613122252im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Baked Light Maps 2 Answers
Problem with 2D Sprites and draw calls 1 Answer
Multiple Shaders vs. Single Texture - Please help me overthink this. 2 Answers