- Modifié
Custom skin sets attachments wrong size and stretched
EDIT (Solved)
Sorry just realized every sprite simply needed Full Rect mesh type enabled.. instant problem solved.
I am trying to use a single default skin to swap out all the images at runtime to accommodate basically an endless amount of characters into the game and when I use the following code I get the attached visuals. I am following the MixAndMatch example and my sprites are all set to 32PPU that I am loading at runtime. The default character in red is the default Spine character that is my player that I have not called the following code on and renders properly.
//set spine animation
var skeletonAnimation = GetComponentInChildren<SkeletonAnimation>();
if(skeletonAnimation != null)
{
var customSkin = new Skin("Custom Skin");
var skin = skeletonAnimation.Skeleton.Skin;
var sourceMaterial = skeletonAnimation.SkeletonDataAsset.atlasAssets[0].PrimaryMaterial;
List<Sprite> sprites = Resources.LoadAll<Sprite>($"Sprites/Spine Textures/{npcData.spineSkinName}").ToList();
foreach (var attachment in skin.Attachments)
{
int slotIndex = attachment.Key.slotIndex;
Attachment templateAttachment = skin.GetAttachment(slotIndex, attachment.Key.name);
Sprite sprite = sprites.Find(x => x.name == attachment.Key.name);
if (sprite != null)
{
Attachment newAttachment = templateAttachment.GetRemappedClone(sprite, sourceMaterial);
//Attachment newAttachment = templateAttachment.GetRemappedClone(sprite, sourceMaterial, useOriginalRegionSize: true); //This did not help either
customSkin.SetAttachment(slotIndex, attachment.Key.name, newAttachment);
}
}
skeletonAnimation.Skeleton.SetSkin(customSkin);
skeletonAnimation.Skeleton.SetSlotsToSetupPose(); // Use the pose from setup pose.
skeletonAnimation.Update(0); // Use the pose in the currently active animation.
}
Any help is appreciated, thanks!
Glad you could resolve the problem, thanks for letting us know!