I am also having trouble with creating a new skin and getting it to appear... any help would be appreciated
Any luck with this Shaka?
This is the example code I'm using, basically I'm creating a clone of the current skin, then applying it. But my Spine character appears blank afterwards (all images dissapear when I set the skin and call SetSlotsToSetupPose)
The skin appears to by applied correctly afterwards, I can verify the attachments by calling skeleton.GetAttachment() so I think it may be something to do with SpriteCollectionAttachmentLoader not creating the NewAttachment correctly, but then why would this work differently from when it is used in Initialisation?
void cloneCurrentSkinAndApply(){
Spine.Skeleton skeleton = skelAnim.skeleton;
Spine.Skin currSkin = skeleton.Skin;
//create new skin to populate
Spine.Skin newSkin = new Spine.Skin("New Skin");
//create an attachment loader to use
SpriteCollectionAttachmentLoader spriteCollectionAttachmentLoader = new SpriteCollectionAttachmentLoader(skelAnim.skeletonDataAsset.spriteCollection);
//vars to use in loop
System.Collections.Generic.List<Spine.Slot> slots = skeleton.slots;
System.Collections.Generic.List<string> attachmentNames;
System.Collections.Generic.List<Spine.Attachment> slotAttachments;
// for each slot in the skin, get the attachment names, image names, make copies of attachments to the new skin
foreach(Spine.Slot slot in slots){
//get the slot index
int slotIndex = skeleton.FindSlotIndex(slot.data.name);
//get attachments from this slot
slotAttachments = new System.Collections.Generic.List<Spine.Attachment>();
currSkin.FindAttachmentsForSlot(slotIndex,slotAttachments);
//get the names
attachmentNames = new System.Collections.Generic.List<string>();
currSkin.FindNamesForSlot(slotIndex,attachmentNames);
//for each attachment in this slot, copy it to new skin
for(int i=0;i<slotAttachments.Count;i++){
Spine.Attachment att = slotAttachments[i];
string attName = attachmentNames[i];
string spriteImageName = att.Name;
Debug.Log("In Slot "+slotIndex+" '"+slot.data.name+"', add attachment '"+attName+"' source image name:'"+spriteImageName+"'");
Spine.Attachment newAtt = spriteCollectionAttachmentLoader.NewAttachment(newSkin, Spine.AttachmentType.region, spriteImageName);
newSkin.AddAttachment(slotIndex, attName, newAtt);
}
}
skeleton.data.AddSkin(newSkin);
skeleton.SetSkin(newSkin);
skeleton.SetSlotsToSetupPose();
}