Unity objects in right z-order but still overlapping – Render Queue Index

Recently I had a problem where I had set up some background gameobjects and sorted them on the z-axis thinking this would automatically render them in the right order always. When the camera moves they start flickering/overlapping each other. At least for the most basic shaders this is not always the case and you should instead set the renderQueue value for the objects that have a strict z-order you want to render them in.

Smaller renderQueue index means it’s closer to the camera and should be drawn on top of anything with a bigger index number.

1
2
3
4
public int renderQueueIndex = 3000;
    void Start () {
        gameObject.renderer.material.renderQueue = renderQueueIndex;
    }
public int renderQueueIndex = 3000;
	void Start () {
        gameObject.renderer.material.renderQueue = renderQueueIndex;
	}
  • Leonardo Baptista

    thank you!

    I solved an issue with SpriteRenderer and SkinnedMeshRenderer z-order using this tip.
    SkinnedMeshRenderer now respect its sortingOrder.