- Editado
tk2d Problem on setting attachment
Greetings,
I'm new to spine and getting some problems when trying to changing new attachment.
Right now we have like "head_001","head_002", etc sets as region attachment. but when I tried to changed it via code with
skeleton = GetComponent<SkeletonAnimation>();
spriteCollectionAttachmentLoader = new SpriteCollectionAttachmentLoader(spriteCollection.spriteCollection);
Attachment attachment = spriteCollectionAttachmentLoader.NewAttachment(skeleton.skeleton.Skin,AttachmentType.region,"head_003");
skeleton.skeleton.FindSlot("head").Attachment = attachment;
skeleton.skeleton.SetSlotsToSetupPose();
The head won't changed, If I erased SetSlotsToSetupPose() , the head will be just disappears.
I'm already rechecking that the sprite is available on our sprite collections and when I'm changing the attachment manually by changing the json file, it changed.
Can you help me, what actually happened or did I missed something?
Thanks before :handshake:
Calling SetSlotsToSetupPose will reset your head slot back to the attachment it has in the setup pose, so don't do that. Your code seems ok. You can pass null for the skin since we know SpriteCollectionAttachmentLoader doesn't use that parameter. Can you use the debugger and step through SpriteCollectionAttachmentLoader#newAttachment to verify it finds the region in your sprite collection correctly? If it does, then debug in SkeletonComponent in the loop after "Count quads and submeshes" and make sure it is using your attachment.
Do you realize that if your attachment is in your JSON you can just do:
skeleton = GetComponent<SkeletonAnimation>();
skeleton.skeleton.SetAttachment("slotName", "attachmentName");
Oh I'm already solved it :rock:
So the problem is my artist organized the image into some categorized folder, so in the json the attachment also will be registered with the folder structures, but I'm just set the attachment it by it's name, not the entire path name like in the json file.
Thank you so much for your assistance :handshake:
Ah yeah, TK2D only uses the name in its atlas, not the whole path.