A little problem with sorting layer ...

Hi everybody,

I thought really I had understood the concept of sorting layers, But unfortunately, i have freeze since several days about a problem of game object ordering, and I have to request now your help.

To be brief, i am just trying to instantiate many game objects inside a “Room” prefab object, in front of others existing elements… in vain !

The structure of my “Room” seems yet to be simple (in bold existing layers of the prefab)

Room

Floor (Sorting Layer : Background, Order : 1)
Walls (Sorting Layer : Background, Order : 2)
Dynamic object 1 (Sorting Layer : Foreground, Order : 5)
Dynamic object 2 (Sorting Layer : Foreground, Order : 6)

Some others details :

  • All my Game Objects are a Z position setted to 0
  • The camera is setted to orthographic, with Z position to -10
  • Each game Objects into “Room” has a Sprite renderer
  • Sorting Layers : Default / Background / Foreground (From Top to Bottom of the panel)

I tried a lot of manipulations (switch my sorting layers, play with natural order into prefab), and nothing changes ! The only solution i have found was to set the Z position of my “Dynamic objects” with negatives values. But I don’t understand why unity react like that !

Could you help me please ?

So you have things like dynamic objects being obscured by walls & floors etc?

Hi! So with Sorting Layers, they are rendered from top to bottom. In other words, Default, 0, 1, 2, 3. Layer 3 will be on top of everything else and layer 0 will be behind Layer 1 :smile:

The Unity Learn video does a great job explaining this :slight_smile: If its too long jump to 1:50 in the video. https://unity3d.com/learn/tutorials/modules/beginner/2d/sorting-layers

Best of luck!!

1 Like

I think use the good layers ordering (my layer titled “background” is before the layer “foreground” in the dedicated panel). Anyway I tried to change this order but i had not seen a different behaviour.

However, I have just remembered me that I also instantiate prefab tiles into my “Floor” layer without setting sorting layers name and order. Theses objects inherit characteristics of parent game object or must I set the same parameters ?

wait, do you have these in UI panels??

Sorry, I misspoke myself, i am not a native english speaker :face_with_spiral_eyes: I would talk about the “window” available here : Edit / Projects Settings / Sorting Layers Tab.

It’s weird because the tiles which have loaded dynamically into the layer “Floor” stay always in front of Dynamic object 1 and Dynamic object 2, even if i change sorting layers name and order…

Could you post some screen shots for me? :smile: and no worries on the English :smile: <3!!!

I don’t get it ! I tried to had some objects directly on the scene and the tiles are sometimes behind, sometimes in front of the tree !
And yet each tile have the same layer name or order values :hushed:

OH!!! I understand!!! :smile: Could you post a picture of the Sorting Layers from the Layers Tab too please! :smile: Then we should be able to get this all worked out :smile:

Level1Floor2 object has no sprite attached, as well as the Tree object. How do their children look like?

Items like Level1Floor2 and Tree are in fact empty game objects in which i included 2d sprites (i do this because i need to load its dynamically to customize each room). Theses objects are stored into a “Resources” folder.

@holliebuckets_1 I could make a screenshot this evening (i am at work now)

1 Like

There’s no sense in changing “order in layer” of a sprite renderer that renders nothing. I guess all your sprite renderers that render the actual sprites have the same “order in layer”.