Hello, I’m currently trying to sort the layers of my sprites so that my player shows on top of my enemy sprites. But no matter what order I put the sorting layers in the enemy always shows on top. I make sure to set them to their layers.
I’ve tried all the layers in every order and nothing changes, apart from if i put the background after the default I can only see the background, even though I cant set it to a sorting layer.
Ive also tried setting them to the same sorting layer and putting them in different orders but still the same results.
I’m stuck at the moment, I’ve had a look at other questions about it but I’m not sure what they are talking about. Any help would be appreciated.
I had the same problem. In my case the issue was that I didn’t have a sprite renderer on the objects I was trying to sort. After adding the sprite renderer I used the field “Sorting Layer” on it. Before I was trying to use the field “Layer” in the top of the Inspector.
Make sure to check the layer and camera depth.
Besides sorting order Unity also uses Camera Depth. If the camera rendering your enemy has a higher depth than the camera rendering your player it will show above the player regardless of sorting order.
The steps which I took are -
- Open Camera in Inspector and set Projection to Orthographic
- select your Enemy sprite in Hierarchy and open it in Projection
- Open Sprite Renderer component(if not there add it by modifying sprite of enemy)…Click on Sorting Layer and select “Add Sorting Layer”
- Now name the new sorting layer “EnemyLayer”
- repeat step 3… just this time select the EnemyLayer instead of adding a sorting layer
- Repeat steps 2-6 for player sprite also (name the sorting layer as PlayerLayer)
N.B.: Because you added PlayerLayer after the EnemyLayer, player will show above enemy!!
you could add as many layer… just order them correctly!