- Home /
Sorting Layers not working?
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.
Can anyone help me, nothing i try changes what order they come up in, the player always goes behind the enemies even though they are on the same point of the Z axis
I'm having the same issue. When I debug, the settings are sticking, but in the game view, the element is still behind an item with a lesser sort order
public LineRenderer catapultLineFront;
catapultLineFront.SetPosition(0,catapultLineFront.transform.position);
catapultLineFront.sortingLayerName = "Foreground";
catapultLineFront.sortingOrder = 3;
The catapultLineFront object is still showing behind a sprite with an order in layer value of 2.
Its not working for me either. Why hasnt anybody answered this question?
Having the same problem here, $$anonymous$$y layers used to work but now It's all jumbled up. It doesn't even matter if I put an object in the background layer (second from the top in the settings) and my foreground layer (bottom of the settings). Any suggestions?
Answer by smoggach · Jan 21, 2015 at 05:25 PM
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.
Thank you for the answer, I think I'm close to fixing it, playing with the camera depth and far/near and it's z position is playing a part in all this weirdness :D
Answer by alex.almeida · Sep 15, 2015 at 01:03 AM
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.
This helped me fix my issue. Thank you.
I added Sorting Layers. Changed the items accordingly and also changed their Order in Layer.
Things I wanted to be on top had a higher Order in Layer than items in the back.
Answer by rahuljain1311 · Jun 03, 2016 at 05:59 PM
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!