So you can enable/disable or change the layer during runtime?
Yep. Sorting layer and sorting order are part of the Renderer class:
https://docs.unity3d.com/ScriptReference/Renderer-sortingLayerName.html
https://docs.unity3d.com/ScriptReference/Renderer-sortingOrder.html
So you could do something like this:
GetComponent<Renderer>().sortingLayerName = "Default";
GetComponent<Renderer>().sortingOrder = 0;
No sorry, I’m referring to the new component in Unity 5.6 called “Sorting Group”.
Ah sorry, my mistake!
Have you tried
GetComponent<SortingGroup>().sortingLayerName = "Default";
Looks like it should work.
https://docs.unity3d.com/ScriptReference/Rendering.SortingGroup.html
I was thinking that too but it seems “SortingGroup” isn’t a type or maybe I’m missing a namespace or something.
UnityEngine.Rendering
These are the kinds of things that should be explicitly called out in the Unity API docs. I know it lists its inheritance, but a simple example on how to call this component would be extremely helpful.
Thank you, ive been looking for where that was. Thought it might be in their documentation but it didnt specifically mention.
Just for future reference since this is an old post being unearthed:
You can indeed find the namespace in the doc header:
and while it’s not always a great idea to rely on your IDE for everything, it’s in your best interest to be using one that can tell you the namespace you’re missing.correct answer:
Just look at the reference code.
To use SortingGroup, you must add UnityEngine.Rendering name space.
first:
using UnityEngine.Rendering;
Then:
GetComponent<SortingGroup>().sortingOrder = 1;
Good luck
Thanks this post was really useful!
