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 !
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
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 ?
Sorry, I misspoke myself, i am not a native english speaker 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…
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
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)
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”.