I have 2 identical dynamic objects in a scene that only batch render when they are close to each other. To rule out my scene being messed up, I also created an empty scene with 2 cubes. When the cubes are close, they batch, when I move them even a small amount apart, they don’t batch. From what I’ve read (and I have read quite a few threads about this), proximity is not supposed to break batching. So what am I missing??? Thanks for any help.
Does the Frame Debugger window offer any clues?
When the two objects are close, it lists as a “Dynamic Batch” in the frame debugger, which is what I would expect. When I get the objects a little further apart on Z axis, it draws one object as a first draw call, and moves the other down the list, after some other objects. If I disable all other objects, the two identical ones always batch together as expected.
There are two other objects in my scene that MUST be disabled for the two identical ones to batch. If I disable those two, the batch always happens. If either of the other two objects are enabled, the identical objects must be close on z to batch.
There is some finnicky automagical depth sorting that takes place when batches are calculated. So what you’re seeing is irritating but normal.
We had to draw lots of objects in a prior project but we optimized everything else well enough we didn’t have to dig into this. There may be a trick to the order you submit objects via the graphics api that might be able to give you more control. I’m speculating, that’s where I’d poke around.
Thanks brownboot67. Looks like you are correct. Changing the camera’s “OpaqueSortMode” to “NoDistanceSort” causes the batches to work as I wanted. Once the depth of the objects got too far apart, Unity prioritized sorting them back to front over batching. My test case is way to small to know if overall performance is gained (or lost) as a result, but at least I know WHY it is happening, and HOW to fix it if I need to. And maybe it will help someone else who really needs it for their project. Thanks again!