- Edited
Per SkeletonAnimation renderQueue
Hi,
I am using Spine in conjunction with NGUI to build my game and I require the ability to have multiple instances of SkeletonAnimation that use the same SkeletonData while being able to adjust their depths individually.
The reason I need this is so I can have the following scenario:
- Object 1 (Skeleton Animation with an NGUI Label on top)
- Object 2 (Skeleton Animation with an NGUI Label on top)
- Have Object 2 overlap Object 1 and be in front of both the SkeletonAnimation and the NGUI Label
I can change the depths of the SkeletonAnimation using (for example):
renderer.material.renderQueue = 4000;
I can also explicitly set the NGUI Label's renderQueue (so I would set it to 4001 in this example).
This works fine and I get the label on top of the SkeletonData, however If I set Object 1 to 4000 & 4001, and Object 2 to 4002 & 4003 I get the Labels on top of everything and the SkeletonAnimations overlapping randomly (same as when two objects have the same draw call and Unity randomly decides which is on top.
So even though I set Object 2's SkeletonAnimation to 4002 (above both of Object 1's parts) Object 1's Label still shows up in front and it's random which pig is in front of the other.
I've tried just about everything I can think of and have not gotten anywhere yet. Anyone have any input ?
- Edited
If you're using Unity 4.3 and above:
Despite not being visible in the Inspector, all Renderers now have settable properties called "sortingLayerID" and "sortingOrder". You can use these properties to control the draw order per Renderer/GameObject (and therefore per SkeletonAnimation).
I know some people in the forums also made a small script to expose the Sorting Layer and Sorting Order properties in the inspector if you really want it to be visible in the inspector or be serialized in the prefab data.
If you're not sure how the new Sorting Layer system works, check out the videos on how Unity 4.3's new SpriteRenderer uses these properties. Or maybe there's something helpful in their docs too. Anyway, the same rules apply to the MeshRenderers that Spine uses, and I'd suppose whatever renderers NGUI uses too.
Thanks, that works for sorting the Spine elements, now I just need to figure out how to get NGUI sorting with it as well.