Hi there, I’m trying to get a bunch of building sprites to batch together into 1 draw calls. I would think the normal dynamic batching would do its job here and also I’ve tried using sprite manager 2’s SpriteManager object and setting the buildings as managed. However, I can’t get it to work.
Here’s a shot of the building’s I’m trying to batch
All the buildings are sharing the same material (which is not modified per building) and it seems pretty clear that there are no other objects inbetween the buildings to prevent the batching due to transparency. I would really expect these buildings to batch together in that scenario. The camera is looking down that street with the buildings on each side, not touching the road nor the cars on the road.
Any idea why the batching does not occur?
Thank you
Ok, I found a solution to my problem but keep in mind that I’d still love to know why the buildings were not being batched. So here’s what I did, it could help people in the future, maybe. Since these buildings are always drawn behind the road, I made another camera with another layer to render all the buildings together and I’m still using SpriteManager to batch them all together as one mesh. The thing is, I added a BuildingManager prefab (which has the SpriteManager component) and assigned that prefab as the manager to my building prefabs so that they know they’re managed sprites, in advanced, and that at run time, I can actually assign the in-scene sprite manager (an instance of the building manager prefab) to them using this bit of (probably unefficient) code.
building.parent = m_BuildingContainer.transform;
(building.GetComponent(PackedSprite) as PackedSprite).managed = true;
(m_BuildingContainer.GetComponent(SpriteManager) as SpriteManager).AddSprite(building.gameObject);
It puts the newly instantiated building as child to the manager and sets it as managed by the manager which I fetch once earlier in the code.
So basically, I’m not too sure what fixed the problem, either being all in another layer or setting the prefabs as managed sprites in advance. But whatever, it’s working and saves me a TON of draw calls