In unity 2d games, there is concept called sorting layer. Sorting layer means camera will render which  game object first or last, in simple words it decide sequences of game objects to render. So if two game objects intersect at same place in game then sorting layer will decide which game object will appear on top on other game objects. That is simple concept in sorting layer.


Why we need sorting layer ?

Well there is one problem that every new developer faced in making 2d game in unity. As know you 2d is 2 dimension view game ( x , y ) so there are same cases in 2d game where two sprites or more than sprite (game object) appear at one place which results visibility of one sprite instead of two. So tackle this type of problem unity provide two features 

1. Order in layers
2. Sorting layers

Lets take a example of three sprites in scene view and that is

1. Background sprite
2. Grass sprite
3. Character sprite

If all sprite have same sorting layer (default) or order in layer (that is equal to zero) then you will see only background sprite in your scene view, you will not see grass and character sprite.

To solve this issue some developer uses z axes to make sprite appear on background sprite, this method work but unity does not recommend you do follow this method or also me because following this method can cause problem in future work like 2d physics.


To Solve this problem using recommended way, you can use order in layer feature. Order in layer take integer value from user and decide its rendering priority. Every game object has its own order in layer property, lets assume I set order in layer for background sprite to zero, grass sprite to one and character sprite to two. In this way, all the sprite will be visible and display as expected. 

You can achieve same result using sorting layer.





Previous Post Next Post