- Home /
Other
Sprite ZFighting in 2.5D game
For some reason my sprite appears behind gameobjects in the game view, despite being on top of them. I assume this has something to do with Z-fighting. Does anyone know how I should go about fixing this?
Could it have to do with the shader I'm using for my blocks?
I've confirmed it has to do with the shader I created. Is there something I need to setup in my shader to prevent this?
Answer by TanselAltinel · May 06, 2021 at 05:29 PM
First, make sure you have this document memorized:
https://docs.unity3d.com/Manual/2DSorting.html
If you have multiple sprites on the same position of Z, the ones lower in the hierarchy will render first. The ones closer to camera will render on top of each other.
However, I'd highly recommend to use Sorting Layers for sprites as it is the new standard for 2D rendering.
https://docs.unity3d.com/Manual/class-TagManager.html#SortingLayers
Now, finally, 3D renderer has no sorting layer exposed in editor, you can use this script to set sorting layer for MeshRenderer component:
Thanks, but I'm pretty sure the issue is related to my shader actually. As when I disable it it works as intended.
Well you didn't specify a 'custom' shader in the question. I'm not a $$anonymous$$d reader :)
I don't know the specification of your shader, but you can use the solution of SortingLayers first.
Secondly, you can select RenderQueue as Transparent in your shader.