[Unity] Mecanim now supported in Unity 4 and 5!
@davidsvson.
There are a lot advantages. Mostly ease of setup, without having to code animation controllers yourself, especially for fun things like blend trees.
I like to roll my own though 'cause sometimes it's hard to get Mecanim to do what you want. Mecanim was really made with 3D animation in mind, whereas I personally like to handle my Spine animations like PlayStation-era 2D sprites.
If Mecanim is what you're used to, it's definitely a good thing to have.
If you've never used Mecanim before, expect to spend some time watching videos and searching how-tos to learn how to use it, as with any part of Unity.
Mitch, you're the man, and you know it.
@davidsvson I concur with Pharan. For instance, I'm currently working on a 2D point and click adventure using Spine. Mecanim is not as suited for this since in our case things as speed or velocity to determine animation states are not fundamental.
Mitch showed it tome using one of his platformer examples though, and you'll find it's perfect for those cases.
Thanks @Mitch @Pharan and @wrongtarget!
I'll not convert to mecanim in my current project but will try it out for the next one.
Great news! I'm seeing a lot of glitches though with Unity 5.
For testing purposes, I moved a character to a Mecanim state machine (previously setting/mixing clips in code).
I have a non-interruptible transition to a state (player turns from right to left), which then transitions (non-interruptible) to "idle" at normalized Exit Time 1.0 (no other conditions). This animation is not played entirely, it often ends up with frames half-way in the turning movement, as if leaving too early
Flipping the skeleton is erratic as well. I can use either
transform.rotation = Quaternion.AngleAxis(facing < 0 ? 180 : 0, Vector3.up);
or
GetComponent<SkeletonAnimator>().skeleton.FlipX = facing < 0;
to flip the skeleton for all left-facing states. It was working before moving to Mecanim, but now it's erratic. Almost seems as if the state machine is messing with the FlipX state of the skeleton (or is it the root bone transform / both?)
Thanks
Rouven
There is a parameter called Mix Mode on the skeleton animator that controls how mixing is applied per mecanim layer. Try setting it to SpineStyle and see if that resolves your issue.
You have no idea how much this helped our workflow when trying to figure out how to sync animations in Bolt networking. Bolt has mecanim support which automagically sync's everything so adding this basically made our day x 500.
Lifesaver.
I'm pretty new to Spine, and I'm having trouble figuring things out. I've tried the Generate Mecanim Controller thing, but I'm not sure how to use it.
So far I was using the "bake all skins" button, which worked fine, I then created a new animator that used the animations from the ones from the bake. It was fine, except that I had to bake stuff again everytime I changed something.
I've tried "Generating Mecanim Controller", and assigning that generated controller to my baked prefab, but it doesn't seem to work. What am I missing ?
@Mitch That didn't change anything, unfortunately. I have disabled and even removed my second (upper body) layer in the Animator, but the issues persist within the Base Layer.
I just noticed the keys that are dropped are only those that attach an image to a slot. All Scale/Rotate/Translate keyframes are applied just fine.
Baking and Generate Mecanim Controller are unrelated. The SkeletonAnimator class acts an interface between mecanim and SkeletonRenderer so it is fundamentally different than baking.
Rouven wrote@[محذوف] That didn't change anything, unfortunately. I have disabled and even removed my second (upper body) layer in the Animator, but the issues persist within the Base Layer.
I just noticed the keys that are dropped are only those that attach an image to a slot. All Scale/Rotate/Translate keyframes are applied just fine.
Would you be willing to send me your exported files w a controller that exhibits this issue? Would love to poke at it heh
Sure, just PM me your email address!
This looks amazing! Will these features be included in the tk2d runtime aswell?
I don't think there's any difference between them in regard to mecanim. Try bringing the animator scripts over.
It worked, thanks
Would love to see this in the official runtime tho, no pressure
Gisle wroteIt worked, thanks
Would love to see this in the official runtime tho, no pressure
Yea; I owe the TK2D runtimes some updates heh. I never use TK2D though not like I get paid for this :wonder:
Hey! First post here :-)
Thanks Mitch for creating the SkeletonAnimator. I just started using Spine (it's been in my todo list forever) with Unity 5. Against all advice, I'm using mecanim since I'm familiar with the kind of state machines you can create with that (and I can't be arsed to create my own State Machine solution from scratch right now). Your SkeletonAnimator is working like a charm! I can "navigate" the state machine and see the animation change to what I created on Spine. Yay!
My next step is to use events. You said they have the same limitation as when you baked the animation using the previous system (SkeletonAnimation?). That makes me happy, because it seems to imply that I can use Spine events with mecanim in Unity 5. The problem is that I don't see where to hook my delegate to listen for events. I've been searching the C# and Unity runtimes but it only seems to exist hooks in AnimationState (old system). The docs also point to AnimationState. Can we listen to Spine events when using mecanim?
soy_yuma wroteYou said they have the same limitation as when you baked the animation using the previous system (SkeletonAnimation?).
He means it's using Unity's Animation events, not Spine-C#'s events.
SkeletonAnimator (and Mecanim) don't touch Spine.AnimationState (where the Spine event delegates live).
SkeletonAnimator also doesn't interface with Spine.EventTimeline.
I'm actually not sure where the events are defined for SkeletonAnimator. I guess in the "dummy" animation clips?
Yeah, they're in the clips (you can inspect them with the Animation window) - and since they're Unity events, they're actually SendMessage-style and calling the function with the same name as the event: http://docs.unity3d.com/Manual/animedit ... vents.html
That is awesome!
I'm still a newbie on Spine+Unity (in case it wasn't evident before), so I didn't know there were Unity events. I'll have a look. Thanks a bunch!
Hi Mitch,
I'm brand new to Spine, so please forgive any stupidity in this post. It looks like I've picked up your latest with the unity package runtime, so I can use the create animation controller action you outlined above. But I'm not really understanding how to configure it, or even the intention here
When I instantiate the controller via Spine->InstantiateMecanim, it looks like it generates a mecanim anim controller that flattens all animations to interface with a single GO: "Game Object.Dummy". How is this configured? I see that the SkeletonData seems to retain linkage to the animator once this is done, which I assume is to aid in iteration. But when I generate a new SkeletonAnimation via Spine->InstantiateSkeletonAnim, it doesn't include the new Animation Controller. When I connect the Spine generated animation controller, it complains that it can't find the Dummy object. Am I missing something fundamental here?
Also, just so I'm clear, this is intended as a "lighter" approach to allowing mecanims to control animation state without incurring (most of) the functionality hits of baking it completely into Unity. Am I completely mistaken here? I hope not, because it seems like exactly what I want.
Thanks!
Jeremy