EDIT: you should use sortingLayerName instead of sortingLayerID (because the sorting layer ID is not the same as its index in the list (except “Default”, which is 0)). The code example from @lassade in the link below clearly demonstrates this. Rest stays the same.
Had the same problem, here is (a hacky quick) solution:
First lets recap: SkinnedMeshRenderer is created
- at runtime
- by SkinnedMeshCombiner
- Sorting Layer and Sorting Order are properties of SkinnedMeshRenderer
So go ahead, open SkinnedMeshCombiner.cs script, and search for this code:
combinedSkinnedRenderer = gameObject.AddComponent<SkinnedMeshRenderer>();
combinedSkinnedRenderer.sharedMesh = new Mesh();
combinedSkinnedRenderer.sharedMesh.CombineMeshes( combineInstances.ToArray(), true, true );
combinedSkinnedRenderer.bones = bones.ToArray();
combinedSkinnedRenderer.sharedMesh.boneWeights = boneWeights.ToArray();
combinedSkinnedRenderer.sharedMesh.bindposes = bindposes.ToArray();
combinedSkinnedRenderer.materials = spriteMeshInstances.sharedMaterials;
As you can see, the new combined mesh is NOT being assigned sortingLayer and sortingOrder. So if you add these two lines (hack):
combinedSkinnedRenderer.sortingLayerID = m_combinedMeshSortingLayerId;
combinedSkinnedRenderer.sortingOrder = m_combinedMeshSortingOrder;
You now have the values assigned, and all should work as expected, Just make sure that you defined those variables
somewhere in the class, and assign the layer id and order you would like.
Yet still, that’s a hacky way, isnt it? We would certainly instead like to have those values in the inspector (especially in case of the SortingLayers - a dropdown there with names of layers to choose from.
If u wanted that, you need a custom Editor override. This might help you immensely, it did help me: