I am using this code to replace a specific sprite.
However, when I create two instances of the same skeleton and switch the sprite, the first skeleton is unexpectedly affected.
I would like to resolve this issue so that changing the sprite in one instance does not impact the other.
public void SetAttachment(string slotName, string attachmentName, Sprite sprite = null, float scale = 0)
{
var slot = _skeletonAnimation.Skeleton.FindSlot(slotName);
var attachment = _skeletonAnimation.Skeleton.Skin.GetAttachment(slot.Data.Index, attachmentName);
var newAttachment = attachment.GetRemappedClone(sprite, attachment.GetMaterial(), false, false, false, false) as RegionAttachment;
newAttachment?.SetScale(Vector2.one * scale);
newAttachment?.UpdateRegion();
_skeletonAnimation.Skeleton.Skin.SetAttachment(slot.Data.Index, attachmentName, newAttachment);
slot.SetToSetupPose();
}
I suspect that the issue might be caused by shared materials or attachments between instances.
What would be the best way to ensure that each skeleton instance maintains its own separate sprite replacement?