Practically all parts of the Spine.Skeleton including bones, slots and attachments are plain C# classes and not UnityEngine.Objects, so they aren't serialized by Unity (saved in the scene or a prefab) but instead just in the text file. This is also because they need to be predictably loaded from the Spine export you provided.
So you would have to add a component that does the initialization (and applies the changes in Edit Mode to be nice).
In Spine-Unity for Spine 3.6, the component code would look like this:
using System.Collections.Generic;
using UnityEngine;
namespace Spine.Unity.Examples {
public class StartWithAttachments : MonoBehaviour {
[System.Serializable]
public class AttachmentSwapItem {
[SpineSlot] public string slot;
[SpineSkin] public string skin = "default";
[SpineAttachment(slotField:"slot")] public string attachment;
}
[SerializeField]
public List<AttachmentSwapItem> attachments = new List<AttachmentSwapItem>();
void OnValidate () { // Apply in Edit Mode
Apply();
}
void Start () { // Apply when instantiated.
Apply();
}
void Apply () {
var skeletonComponent = GetComponent<ISkeletonComponent>();
var skeleton = skeletonComponent.Skeleton;
if (skeleton == null) return; // In case of prefab editing?
foreach (var swapItem in attachments) {
if (string.IsNullOrEmpty(swapItem.slot)) continue;
var skin = string.IsNullOrEmpty(swapItem.skin) ? skeleton.Data.DefaultSkin : skeleton.Data.FindSkin(swapItem.skin);
int slotIndex = skeleton.FindSlotIndex(swapItem.slot);
var attachment = string.IsNullOrEmpty(swapItem.attachment) ? null : skin.GetAttachment(slotIndex, swapItem.attachment);
skeleton.Slots.Items[slotIndex].Attachment = attachment;
}
// Simpler version
// foreach (var swapItem in attachments) {
// if (string.IsNullOrEmpty(swapItem.slot)) continue;
// skeleton.SetAttachment(swapItem.slot, swapItem.attachment);
// }
}
}
}
We've made some changes in Spine-Unity for Spine 3.6 to be cleaner and limit the attachment search, but the gist of it would be the same in 3.5
Keep in mind that setting the attachments directly is pretty low level and can be overwritten by animations that also key/set attachments, or any of your code that makes calls to skeleton.SetToSetupPose()
or related methods.