In Unity, Spine skeletons are indeed rendered as mesh renderers, and the sorting is handled through a combination of Unity's sorting systems and Spine's draw order.
How Sorting Works
Within a single skeleton mesh, attachments are drawn according to the Slot draw order you defined in Spine. The spine-unity runtime generates the mesh with triangles following this order.
Between different meshes (like your character and the horse sprite), Unity uses multiple factors to determine rendering order:
- Camera depth
- Material.renderQueue
- Shader's Queue tag
- Sorting Group components (which you're already using)
- Sorting Layer and Order in Layer
- Distance from camera
Solution: Use SkeletonRenderSeparator
To get your character's legs on either side of the horse, you need to split your skeleton's rendering into multiple parts. The SkeletonRenderSeparator component is designed exactly for this purpose.
Here's how to set it up:
Add the component: Right-click on your SkeletonAnimation/SkeletonRenderer in the inspector and choose "Add Skeleton Render Separator"
Define separator slots: Choose the slot where you want to split the rendering. For example, if you want the back leg behind the horse and front leg in front, select the slot that sits between them in draw order
Add parts renderers: Click "Add the missing renderers" to create the required SkeletonPartsRenderer GameObjects
Set sorting: Each SkeletonPartsRenderer has its own "Sorting Layer" and "Order in Layer" properties. Set these so that:
- Back leg part has a lower order
- Horse sprite has a middle order
- Front leg part has a higher order
Your point follower can move the horse sprite to the correct position, and the sorting order will ensure the legs render on either side of it.
About Z-Position
Spine shaders typically don't write to the depth buffer by design, so z-position alone won't control sorting in the standard setup - you need to use the sorting layer/order system described above.