- Modifié
Skeleton ghost not visible
Hi guys,
Did someone figure how to change SKELETON GHOST layer for visibility, in my case I got an sprite background who is rendering in front of the ghosting effect, if I turn off the background sprite, the ghost is visible.
:beer: Thanks !
I'm getting the same issue. The ghosts seem to render in back of every other sprite in the scene.
However, digging into the SkeletonGhost shader script, setting "ZWrite" to "On" fixed the issue.
With this fix, though, there's a new problem with the transparency in each region attachment. In fact, the texture's alpha channel turns into a solid color.
Does anyone know how to "reactivate" the alpha channel?
Same problem here. Changing ZWrite fixed one issue but created a whole bunch of others, so an official fix would be appreciated.
You'll want to use Unity's Sorting Layer system.
ZWrite won't work well with alpha blended sprites— and certainly with translucent or additively blended sprites.
Changing the sorting layer through code will need some extra work.
(1) You need to access the SkeletonGhostRenderer[] pool
array of the SkeletonGhost
class. (you can make it public. It's private right now.)
(2) Each SkeletonGhostRenderer
in pool has a MeshRenderer meshRenderer
. (you can make it public. It's private right now).
(3) Like any UnityEngine.Renderer
, MeshRenderer
has .sortingLayerID
, .sortingLayerName
and .sortingOrder
. You'll have to for-loop through all the meshRenderers and set them accordingly whenever you want to reorder.
http://docs.unity3d.com/ScriptReference/Renderer-sortingLayerID.html
http://docs.unity3d.com/ScriptReference/Renderer-sortingLayerName.html
http://docs.unity3d.com/ScriptReference/Renderer-sortingOrder.html
The end result would be something like this in your script.
var ghostRendererArray = mySkeletonGhost.pool;
for (int i = 0; i < ghostRendererArray.Length; i++) {
// This gives each renderer the appropriate sorting order (given by int mySortingOrder)
ghostRendererArray[i].meshRenderer.sortingOrder = mySortingOrder;
}
There's no way to have it render naturally based on Z position? The rest of my game does that, I actually never touched the sorting layer and order system...
I haven't used it before so I'm not familiar what kind of shader SkeletonGhost uses.
But you will notice that Spine SkeletonRenderers/SkeletonAnimations do render based on a distance from the camera.
It doesn't use ZWrite. The camera just decides what to render first based on distance.
The whole thing. Not parts by writing to and reading from the depth buffer like ZWrite does.
I can't investigate this right now. Super under the weather. But I hope this info helps you for now.
02 Jan 2016 6:57 pm
Just to follow up, I think I've learned why it's hiding behind your objects.
It wasn't a shader thing.
SkeletonGhost and SkeletonRenderer belong to the same render queue so that wasn't causing anything strange.
But what it does mean is that SkeletonGhost relies on sorting layer and sorting order to render behind. SkeletonGhost passes (sortingOrder - 1) as the sorting order of the ghost elements: https://github.com/EsotericSoftware/spine-runtimes/blob/master/spine-unity/Assets/spine-unity/Ghost/SkeletonGhost.cs#L103
Unity's render system prioritizes grouping objects according to sorting order BEFORE letting the distance of objects affect the render order. If all your objects belong in the Default sorting layer, then anything of a sorting order less than 0 will be behind everything that is 0, including meshes that are whatever distance far away from the camera.
I've fixed SkeletonGhost and SkeletonGhostRenderer so you can use it with your type of workflow. See the new inspector items under the "Sorting" header. The default is still the 2D/sorting order way.