I’ve been leveraging the SpriteManager to improve my game’s performance (thanks Brady!), but I’ve run into a problem. The sprites sometime overdraw particle systems that are closer to the camera, and I haven’t been able to run down a way to address this. Has anyone else experienced such an issue?
I’m not sure, but I think Unity does its own depth sorting for meshes. I’ve noticed that you can usually get one mesh (and SpriteManager is nothing but a single mesh) to render “in front” of, or “behind” another mesh if it has polygons inside it that are nearer to the camera than the other mesh, PROVIDED that the bounds of the mesh have been recalculated for that mesh. So for this to work with SpriteManager, try this:
Make sure none of your sprites are as close to the camera as the particles in your particle system (which is also a single mesh). Then, make sure the bounds of your SpriteManager mesh are current by calling “UpdateBounds()”. This should make sure Unity knows that the bounding volume for your SpriteManager mesh does not extend as near to the camera as that of the particle system.
I’ve found in a handful of tests I’ve done that this will get the desired result. But I’ve not tested it enough to know for sure if it works in all situations.