• Unity
  • Set Sorting Layer Of Skeleton Animation

Related Discussions
...

Hello

Quick question I could not find the answer to.

How do I set the sorting layer for a SkeletonAnimation in code?

I tried checking it and the base class and I don't see any "sortingLayer" setter.

It's available in the inspector but I cannot find it in the code :wonder:

SkeletonAnimation uses a MeshRenderer to render.
Since MeshRenderer doesn't expose its sorting properties in its inspector and a lot of people looked for them, we exposed them in the SkeletonAnimation inspector. But they belong to the MeshRenderer.

These are the properties:
https://docs.unity3d.com/ScriptReference/Renderer-sortingOrder.html
https://docs.unity3d.com/ScriptReference/Renderer-sortingLayerID.html
https://docs.unity3d.com/ScriptReference/Renderer-sortingLayerName.html

GetComponent<MeshRenderer>().sortingOrder = 2; // set the order in layer to 2
int sortingLayerId = GetComponent<MeshRenderer>().sortingLayerID; // get the sorting layer ID.

Ah ok thank you very much for the explanation!