I have a sorting layer on one gameObject and it is supposed to be in front of another object, gameObject 2, and it works. However, gameObject 2 has a costume switching function, and after it switches, it goes in front of gameObject 1 DESPITE THE SORTING LAYERS. How do I solve this? I’ve tried sorting groups putting them on the same layer and then just using order in layer, nothing seems to work. Thank you for reading.
Three (3) primary ways that Unity draws / stacks / sorts / layers / overlays stuff:
In short, as far as the Standard Rendering Pipeline,
-
The default 3D Renderers draw stuff according to Z depth - distance from camera.
-
SpriteRenderers draw according to their Sorting Layer and Sorting Depth properties
-
UI Canvas Renderers draw in linear transform sequence, like a stack of papers
If you find that you need to mix and match items using these different ways of rendering, and have them appear in ways they are not initially designed for, you need to:
- identify what you are using
- search online for the combination of things you are doing and how to to achieve what you want.
There may be more than one solution to try.
For instance, you may even use multiple co-located cameras to more-explicitly control apparent draw ordering.
Additional reading in the official docs:
And SortingGroups can also be extremely helpful in certain circumstances:
Other rendering pipelines may have other ways of layering (HDRP and URP). Go see the latest docs for details.
Yeah, it does sound strange. Do you have a screenshot of the Scene and the Inspector. Just so it’s easier for us to identify the hitch.
Curious also, does your costume switching function assign a Sorting Layer and Order in Layer when switching between costumes?
I got it fixed. I apologize for taking up your time:(