I need to swap character weapons. I did the same like in "Mix and Match" example.
But when I launch the game, only weapon is seen, and character body disappears. It even is not baked into a new atlas.
void ApplyWeapon(int weapon)
{
var skeleton = skeletonAnimation.Skeleton;
var templateAttachmentsSkin = skeleton.Skin.Name;
customSkin = customSkin ?? new Skin("custom skin");
var templateSkin = skeleton.Data.FindSkin(templateAttachmentsSkin);
int gunSlotIndex = skeleton.FindSlotIndex(gunSlot);
Attachment templateGun = templateSkin.GetAttachment(gunSlotIndex, gunKey);
Attachment newGun = templateGun.GetRemappedClone(gunSprite[weapon], sourceMaterial);
if (newGun != null) customSkin.SetAttachment(gunSlotIndex, gunKey, newGun);
if (repack)
{
var repackedSkin = new Skin("repacked skin");
repackedSkin.Append(skeleton.Data.DefaultSkin);
repackedSkin.Append(customSkin);
repackedSkin = repackedSkin.GetRepackedSkin("repacked skin", sourceMaterial, out runtimeMaterial, out runtimeAtlas);
skeleton.SetSkin(repackedSkin);
if (bbFollower != null) bbFollower.Initialize(true);
}
else
{
skeleton.SetSkin(customSkin);
}
skeleton.SetSlotsToSetupPose();
skeletonAnimation.Update(0);
Resources.UnloadUnusedAssets();
}
Settings: http://skrinshoter.ru/s/241017/YXWh4h6b
Result: http://skrinshoter.ru/s/241017/JD05goC2
I solved this puzzle.
I replaced this line:
repackedSkin.Append(skeleton.Data.DefaultSkin);
with this one:
repackedSkin.Append(templateSkin);
And then I set a character atlas image "Read/write enabled" property to "true"
Seems like skeleton.Data.DefaultSkin is undefined somehow or empty. Maybe I need to setup a "DefaultSkin" property in the source Spine scene? But I don't know how. So the problem is translating to "What is the difference between your and my sources?"
And it works only if repack is enabled.