- Editado
Switching Skeletons
Hello,
I have just got into Unity fairly recently (I have alot of experience animating and coding in Gamemaker with spine) and have been working on implementing some of my spine animations. I've been trying to look online to answer all of my programming related questions but am quite frankly not finding many solutions. Or maybe im just not experienced enough in Unity to understand the answers I am finding.
Anyways my first question is if it is possible for me to swap out a skeleton for another via code. This is fairly straightforward in something like gamemaker. Basically I have 3 skeletons, a down, side and up version (kind of like a classic topdown zelda game) and each of these skeletons have 3 animations so far. (Walk, Idle & Run) Animation switching and blending works as I would expect. But how on earth would I switch the skeleton out?
If so can you point me in the correct direction?
One last question. Also how would you go about flipping a skeleton? Thank you all in advance!
Harald posted a little snippet for switching SkeletonDataAssets over here. It's not recommended though, and I think you'd probably get better results for your specific use-case by having three child GameObjects with your Down/Up/Side variants setup, and then enable/disable them visually as your character changes direction.
As for flipping, that's an easy one!
Thanks @Cranktrain for answering!
@[excluído]
Please note that Spine offers even better ways for typical 8 (or 4) direction movement, which also allows for transition animations, etc. Amoung other forum threads, Erika described it in this forum posting here. There is also a twitch stream linked in the posting that shows everything in detail.
If you still want to switch skeletons, please do not switch them via changing the assigned SkeletonDataAsset
and re-initializing it every time, as this would be very wasteful. Instead you should just have one additional GameObject (e.g. as child Transform of your character's main GameObject) for each direction skeleton. Then when changing directions, you disable the active direction skeleton and enable the new direction skeleton. This way everything is only initialized once.
Thank you guys for answering! I ended up doing as suggested and just have the visibility toggle based upon the players direction. The animations are all children of a gameobject and it works perfectly!
Glad to hear, thanks for getting back to us!