I was following the tutorial here http://en.esotericsoftware.com/spine-examples-mix-and-match
However, I could not find any tutorials as to how I could change an item while running it in Unity using multiple Skins like that.
So for example, I have this test character, it contains 2 faces and 2 swords. I created a Unity project with a button that is supposed to swap out the iron_sword with the gold_sword, I also wanted it to keep the currently worn face.
The overall behaviour would be equivalent to an "Equip Sword" button.
using UnityEngine;
using Spine;
using Spine.Unity;
public class AttachmentSwapper : MonoBehaviour
{
public SkeletonAnimation skel;
public void SwapSword()
{
Skeleton skeleton = skel.Skeleton;
Skin customSkin = new Skin("custom");
int faceSlot = skeleton.FindSlotIndex("face");
int swordSlot = skeleton.FindSlotIndex("sword");
// i want to keep the current face in the customSkin
customSkin.SetAttachment(faceSlot, "face", skeleton.GetAttachment(faceSlot, "normal_face")); // this should probably need something like skeleton.GetCurrentAttachment(faceSlot);
// i want to change the sword to "gold_sword"
customSkin.SetAttachment(swordSlot, "sword", skeleton.GetAttachment(swordSlot, "gold_sword")); // probably isn't done this way...
skeleton.SetSkin(customSkin);
skeleton.SetSlotsToSetupPose();
}
}
However this approach seems to be closer to what I'd do if I wanted to attach Sprites, not copy Skin slots to a new skin for the character to wear.
But as my character is comprised of slots dictated by Skins, it seems like there's no attachments, just slots.
It seems this is why the script above throws errors too. It returns null when it tries to do skeleton.GetAttachment(), no matter what name I give it.
I am so lost though, every tutorial that I found seems to be about Spine 3.6 or some other older version and doesn't work anymore. Is there any way to do what I need?
This is how my character is setup: