- 수정됨
Combining Skins - Additive
Hello, I am working on creating a system for showing several skins at once and I could use some help. First I'll describe the setup I'm trying to achieve:
We have two base character silhouettes that we want to share one skeleton: a male character and a female character. We also have dozens of outfits that we want to be able to add to each character at runtime. We have a variety of hairstyles we want to be able to add at runtime as well.
This is the setup I am currently trying to create:
- Create two skins in Spine for the base animations: one for the male character and one for the female character.
- Create a skin for each outfit in Spine that goes on the same skeleton as the base skins
- In Unity create a new skin using the character skin as a base and add all the attachments from the outfit skin to the new skin.
- Use a placeholder slot for the hair that is a child of the head bone and attach the hairstyle sprites at runtime.
Now for the actual question! I'm currently hung up on the third part of the implementation: specifically creating a duplicate of one skin and adding another skin as new attachments on top of it. I have looked for ways to do this but I can't seem to find any. Everything I have found related to combining skins or mix and matching swaps out one image on an attachment for another, but I am looking to create a new skin that is the combination of two entire skins. The biggest issue I've run into is I can't seem to find a way to get all the attachments on a skeleton or a skin. I also can't find a way to see how many attachments are on a skin (otherwise I could just use a simple for loop and use GetAttachment). I could just tell the script how many slot indexes to loop over but if we decided to change the skeletons later then I have to update the code to match.
If anyone knows how to get around those issues or has a suggestion for another setup I can try I would really appreciate it!
Thanks,
Ceraph
It seems like you're describing 2 separate skeletons, with many skins (one for each armor set) - and a single slot that changes for the hair.
I had wanted to avoid needing to duplicate the skeleton (since they will share animations) but talking to the artists this seems like a doable solution. Thanks for the advice! I would still be interested to know how to do the other solution though, if only just to understand the engine better. If anybody knows that would be awesome.
I don't believe the system is structure to handle what you're describing.
You can jerry-rig it -
1 skeleton
2 skins - male/female
Then attach a separate skeleton per armor or weapon slot, then change skins on that 2nd skeleton.
But.... why would you do this to your animators? (Answer: WoW did this to their animators in order to ensure multiple colors of the same shape of red hat could match the animation of the characters)
@Ceraph You're actually doing it better than most users instinctually do it.
Combining two skins, isn't a runtime feature yet but it's definitely coming. I've suggested it before and @Nate thinks it's a good idea.
That said, Skins are pretty much just Dictionaries internally, so combining skins is actually already doable without too much work in code, even without (for now) official support.
I added a copy constructor and a very simple AddFromSkin method in this version of Skin.cs: https://gist.github.com/pharan/919bf0ba88beffc62a51046056171885
This is the new code highlighted: https://gist.github.com/pharan/919bf0ba88beffc62a51046056171885#file-skins-cs-L49-L59
And sample usage would be like this:
void Start () {
// Get your original skins.
Spine.Skin guy = skeletonAnimation.skeleton.data.FindSkin("guy");
Spine.Skin additional = skeletonAnimation.skeleton.data.FindSkin("stuff");
// Combine them.
Spine.Skin combined = new Skin("combined", guy); // New copy constructor
combined.AddFromSkin(additional); // Add items from another skin.
}
Hi,
When you combine skin like that, how are they combined ? Does the second one override the first ones for each slot image it has ?
Thanks
That's up to you. You can change the code however you want.
This version just overwrites attachments if they already existed in the first one.
@Pharan thanks for the script! This looks really useful, I'll have to try it out.
Thanks,
Ceraph
The link seems to lead to a missing page
This thread is from 2016. Can you post a new topic and describe what you need?
You may also find something useful here: https://github.com/pharan/spine-unity-docs/blob/master/Mix-and-Match.md
Actually the new link u given me is all I needed. Thanks a lot :yes: !