• RuntimesBugs
  • Change PathAttachment by code

Hi
(First some context) I have a spine that should have 9 movement animations but instead of that, we have only 1 path animation and by code i change the starting point and end point, it works individually.

`private void SetAnimationPath(SpinePlayer spinePlayer, Vector3 startPos, Vector3 endPos)
{
//First approach
//Skin skin = spinePlayer.SkeletonData.DefaultSkin;
//PathAttachment path = (PathAttachment)skin.GetAttachment(2, "multiplier_path");

        //Second approach
        PathAttachment path = (PathAttachment)spinePlayer.Skeleton.GetAttachment(2, "multiplier_path");

        //Main code
        path.Vertices[0] = (Single)startPos.X;
        path.Vertices[1] = -(Single)startPos.Y;
        path.Vertices[2] = (Single)startPos.X;
        path.Vertices[3] = -(Single)startPos.Y;
        path.Vertices[4] = (Single)startPos.X;
        path.Vertices[5] = -(Single)startPos.Y;

        path.Vertices[6] = (Single)endPos.X;
        path.Vertices[7] = -(Single)endPos.Y;
        path.Vertices[8] = (Single)endPos.X;
        path.Vertices[9] = -(Single)endPos.Y;
        path.Vertices[10] = (Single)endPos.X;
        path.Vertices[11] = -(Single)endPos.Y;
    }`

But now i have 3 objects with the same spine and when i play the 3 of them at the same time, all of them start and end in the same location.
When debugging i noted that they are sharing the same info at "path.Vertices" so when i change the path for 1 and change it for all of them.
Do anyone knows a way to modify the path of each spineplayer individually?

Related Discussions
...

By default the attachments (and animations, skins, bone data, slot data, etc) are shared across skeleton instances. That way the data is only loaded once, no matter how many skeleton instances you have. See:

Изображение удалено из-за отсутствия поддержки HTTPS. | Показать


From: http://esotericsoftware.com/spine-runtime-architecture

You can make a copy of the attachment for each skeleton instance, so you can change one without affecting the others. You'd set the attachment copy on the slot of the appropriate skeleton instance.

If you use skins, the skeleton gets attachments from the skin, eg when Skeleton setAttachment is called or when an animation applies an AttachmentTimeline. If you don't use those to change your particular attachment copy, then you don't need to worry, you can just set the attachment on the slot. However if you do, for each skeleton instance you'd want to make a copy of the skin, then change the attachment in the skin.

Hi
I tried dynamically copying the skin and worked perfectly
Thanks

  • Nate оценил это.