Hey all,
In the project I am working on, there are multiple character variants on-screen at the same time, and I need to generate/modify skins dynamically at runtime. In particular, this involves randomized face/body/outfit swapping, as well as held-item swapping. Each item shares the same animation data, but is itself composed of multiple different skinned mesh attachments that have slot attachment animation keys. In order to permit these item mesh sets to be swapped around at runtime, the attach keys use placeholders, not concrete attachments.
Everything appears like it can be set up correctly from within the editor, but I am having trouble figuring how to implement the runtime aspect of this feature.
Specifically, I am working in the C runtime, and I am not certain how best to go about creating a dynamic skin at runtime that will assign the placeholder values with concrete attachments (for keyed slot attachment animation).
Based on my knowledge of the runtime, my expected approach was:
- Create a new spSkin.
- Copy all attachments from an specified existing skin (most likely "default") into the new skin.
- Rename or copy desired attachments within the new skin to the names of the placeholders.
- Call spSkeleton_setSkin(skeleton, skin) on the skeleton.
- Update the skin attachment and call spSkeleton_setSkin again whenever the held item or outfit changes.
I can see a number of other possible approaches to this task, but all of them run into the same issue, which is an apparent inability to deep-copy a skin/attachment instead of simply referencing it. According to the source code, the spSkin owns its attachments (calling dispose on them), which means I cannot safely share the attachments them between multiple skins. Moreover, the skin's entries are private data, so a deep copy solution appears to be strongly and explicitly discouraged.
Is there a way you would suggest implementing this feature? My hope is that I'm misunderstanding the usage idiom, and that there is a safe and straightforward way to accomplish what I need. (I am reluctant to take the brute-force approach of intrusively implementing a spSkin_clone(), spAttachment_clone() function, etc..., as the propagation of vtable changes alone would create a significant maintenance hassle when integrating future Spine versions.) An alternative approach would be to have a placeholder name-aliasing system per-spSkeleton that indirects attachment names through a lookup table.
Let me know what you think! 🙂
Thanks,
Tim A.
P.S. Here is a stack of pancakes doubling as a birthday cake: :cake: