Mixing sprite renderer and mesh renderer sorting layers
I need to mix my sprites and my 2d meshes in a way that the layer system basically doesn't differentiate them, I can specify layer groups like Foreground, Background etc and order in layer attributes inside those groups. Doesn't dfferentiate means if I make a SpriteRenderer_first
's order in layer 2, MeshRenderer_second
's order 1 and SpriteRenderer_third
's order 0, I see them in the appropriate order: first, second, third, so it doesn't matter if they are meshes or sprites, the order controls it all.
Now , I have seen former posts like this offering some simple code but I'd like to know if, using Unity 5.6.2f1, this has changed, meaning I don't have to code for this? Or if I have to code, how to mix mesh and sprite renderer's layer order like I told? Thanks in advance.
Answer by herb_nice · Apr 07, 2018 at 04:19 AM
had this same problem and found that putting a Sorting Group on the game object with the mesh renderer will allow you to specify it's sorting order among the sprite renderers. dunno if component order makes a difference, but mine is listed above the mesh filter and mesh renderer in the game object.
@herb_nice -- that worked perfectly for me.
@agiro -- you mentioned a "simple code" solution. Do you mean this: inside the script attached to the GameObject that has the mesh, inside the Start() method, I put:
GetComponent<$$anonymous$$eshRenderer>().sortingOrder = 9;