To determine whether a 2D object renders in front of another, Unity uses the following criteria. If Unity renders a GameObject before another, the first GameObject appears behind the other.
The following applies to sprites, tiles, and sprite shapes.
Sorting layer: Unity renders a GameObject earlier if its Sorting Layer is higher in the list in the Tags and Layers window. For more information, refer to Arrange 2D GameObjects in layers.
Sublayer: Unity renders a GameObject earlier if its Order in Layer property has a lower value. For more information, refer to Arrange 2D GameObjects in layers.
Render pass order: Unity renders a GameObject earlier if the Render Queue property of its material is lower. For more information, refer to Set the order within a layer and sublayer.
Distance: Unity renders a GameObject earlier if it’s further from the camera. The distance calculation depends on the Projection property of the camera, the Transparency Sort Mode property, and the Sort Point if the GameObject is a sprite. For more information, refer to Set the order within a layer and sublayer.
Note: By default, all sprites are on the same Default sorting layer, have the same Order in Layer value, and have the same Render Queue value. If you don’t change these settings, Unity uses the distance to camera as the first differentiator for sorting.
Shader and material properties: Unity renders GameObjects with the same shader and material properties together in a group. The order Unity uses to render the different groups isn’t guaranteed.
If all the previous values are the same for two GameObjects, Unity has an internal render queue order that determines which GameObject renders first. This order isn’t guaranteed and you can’t control it.
The order can be different depending on your project.
Note: If you add a set of GameObjects to a Sorting Group component, the group renders as one unit on a single sorting layer and sublayer. You can still sort the GameObjects inside the group. Use Sorting Groups to avoid instances of prefabsAn asset type that allows you to store a GameObject complete with components and properties. The prefab acts as a template from which you can create new object instances in the scene. More info
See in Glossary mixing with each other. For more information, refer to Prevent 2D GameObjects mixing in sorting layers.