- Modifié
Attachment not following animation after setting prev skin
Hello, I am currently having trouble re-setting a cached skin back to a skeleton animation.
this is the current code, and i've tried many method trying to have it working but it doesn't seem to help.
public void AssignCachedSkin(Skin _skin)
{
if (skeletonRenderer.valid && skeletonRenderer.Skeleton.Skin != null)
skeletonRenderer.Skeleton.Skin.Clear();
if (holderSkin == null)
holderSkin = new Skin("cached_repacked_skin");
holderSkin.CopySkin(_skin);
repackedSkin = holderSkin.GetClone();
skeletonRenderer.Skeleton.Skin = holderSkin;
skeletonRenderer.Skeleton.SetToSetupPose();
skeletonRenderer.Skeleton.UpdateWorldTransform();
skeletonAnimation.AnimationState.Apply(skeletonRenderer.Skeleton);
skeletonAnimation.AnimationState.Update(0f);
}
the original skin was created with this line of code,
repackedSkin = holderSkin.GetRepackedSkin("repacked_skin", skeletonRenderer.SkeletonDataAsset.atlasAssets[0].PrimaryMaterial, out Material runtimeMaterial, out Texture2D runtimeAtlas, maxSpriteSize);
it is then stored in a static variable, the skin will then re-applied after a scene changed.
i've also tried upgrading to spine-unity-3.8-2021-07-12 but the problem seems to still be there.
the attachments seems to go back to a placeholder position set in Spine instead of the character's hand.
Can I know how can I fix this problem? Thanks
fakegood a écritHello, I am currently having trouble re-setting a cached skin back to a skeleton animation.
I'm afraid I don't understand what exactly you are trying to achieve and what you are getting as a result instead. Could you please describe what you mean by "re-setting a skin back to a skeleton animation"? Did you mean "at a skeleton animation" instead?
fakegood a écritthe attachments seems to go back to a placeholder position set in Spine instead of the character's hand.
What do you mean by placeholder position? Do you mean they reset back to the default skin's attachment? What does your default skin contain (e.g. when you select it in the preview of the SkeletonDataAsset in the Inspector)?
fakegood a écritskeletonRenderer.Skeleton.Skin.Clear();
In general this line looks very dangerous and could be the cause of your problems. Are you sure that you are not clearing one of the SkeletonDataAsset's skins (the shared skin data) here instead of clearing a copied instance skin object?
sorry i did not do a good job asking the question. let me try that again.
there's 2 same SkeletonAnimation in 2 different scenes. call it Scene1 and Scene2.
i first generate a skin with
repackedSkin = holderSkin.GetRepackedSkin("repacked_skin", skeletonRenderer.SkeletonDataAsset.atlasAssets[0].PrimaryMaterial, out Material runtimeMaterial, out Texture2D runtimeAtlas, maxSpriteSize);
and stored it in a static variable from Scene1.
after switching scene from Scene1 to Scene2, I will call SkeletonAnimation.Initialize(true) and AssignCachedSkin() (method from original question) in Scene2.
AssignCachedSkin parameter is taken from the skin stored in the static variable previously in Scene1.
However, the attachments are not animating at the desired position. It works perfectly fine when I call the full SetAttachment flow instead of AssignCachedSkin()
skeletonRenderer.Skeleton.Skin.Clear(); this line was added out of desperation.. and it did not seems to solve the issue. I will remove that line
What do you mean by placeholder position? Do you mean they reset back to the default skin's attachment? What does your default skin contain (e.g. when you select it in the preview of the SkeletonDataAsset in the Inspector)?
we combined a lot of skins together, our default skin got nothing other than shadow.
Thanks for the additional info.
fakegood a écritHowever, the attachments are not animating at the desired position.
Do you mean that their location is off, but moving along with the correct bone? Could you perhaps post a screenshot that shows the issue? Does this also happen when you are not playing any animation at all?
Are you perhaps assigning (or passing as parameter) the already-repacked texture where the original texture should be assigned?
Could you perhaps create a minimal Unity project that still shows this issue and send it as a zip package to contact@esotericsoftware.com (shortly mentioning this forum thread URL so that we know the context)? Then we can have a look at what's going wrong.
Harald a écritDo you mean that their location is off, but moving along with the correct bone?
it's really hard to explain the situation, it doesn't look like it's animating at the correct bone. different animation does different thing, some animation will drag that attachment back to the position it supposed to be, some animation like running, death or something idling, those specific attachments will just go away.
I will try to make one project to demonstrate the problem and sent it over to the email. i believe that would help a lot in this question.