For a game I am making, I need 2D sprites to always render in front of the other 3D GameObjects in the scene (not the UI).
I have tried using sorting layers, but they don’t seem to work in this case. It may be because I’m working with 3D objects, and I could not a way to set a sorting layer for a 3D GameObject.
Normal layers aren’t working either, no matter what I set it to, even UI, the sprites will still render based on their distance from the camera.
What I did to achieve that was to make a copy of the Default Sprite shader code and added a ZTest Always to the SubShader.
You can download a ZIP of built in shaders at the Download Archive.
The DefaultSprite shader is located in the DefaultResourcesExtra folder. Then you’ll want to add the ZTest Always line which would now look something like this.
Cull Off
Lighting Off
ZWrite Off
ZTest Always
Blend One OneMinusSrcAlpha
Now apply that new shader onto the sprites you want to always render in front of 3D objects