I have a scene with a moderately high amount of skinned mesh renderers, and multiple cameras stacked together (for different depth compositing effects and GUI layers etc.)
Upon profiling a build on device, I noticed a massive portion of my frame time goes to:
- FinalizeUpdateRendererBoundingVolumes (5.55ms)
- SkinnedMeshFinalizeUpdate (5.54ms)
- SkinnedMeshUpdateAllNeeded (2.22ms)
- SkinnedMeshFinalizeUpdate (5.54ms)
The reason for these large timings seems to be that each and every camera recalculates all skinned mesh bounds, even if they’re not part of their culling mask. For example, each GUI camera will calculate mesh bounds for NPCs in the scene, even though they do not render them.
As far as I can tell, this behaviour has been marked as “by design” by Unity: Unity Issue Tracker - SkinnedMeshRenderer is updated for a Camera when it's culling mask does not intersect the renderer
Furthermore, it does not seem to matter that these bounds have not changed between each camera render call; my best guess is that Unity recalculates them because they could have changed.
Needless to say though, with 5ms+ of CPU cost, I can’t afford to keep these useless calculations, but I also can’t figure out a way to skip them. Is there something I could do?
The only thing I can think of is setting forceRenderingOff manually on all skinned mesh renderers before other cameras render, but it’s pretty complex and this too would have a CPU cost.
Or could I somehow tell Unity to only calculate the bounds once per frame, and reuse those for other cameras?