• Runtimes
  • [Unity] Mecanim now supported in Unity 4 and 5!

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.

Related Discussions
...

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 escreveu

@[excluído] 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!

13 dias depois

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 escreveu

It 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:

10 dias depois

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 escreveu

You 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?

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!

18 dias depois

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

There are 3 ways to go from Spine


making things move in Unity at the moment.

1) Instantiate -> SkeletonAnimation
This is the "Spine" way. All features supported.

2) Instantiate -> Mecanim (or SkeletonAnimator)
This creates a scene graph object and a dummy RuntimeAnimationController with proxy AnimationClips that match the name and length of the SkeletonData associated with your Spine JSON or Binary file. The Dummy property is there simply so Mecanim thinks the animations are the correct length. The SkeletonAnimator component applies animations using the Spine API's Animation Mix and Apply functions. This allows use of Mecanim graphs with the Spine API directly which is a standard Unity animation workflow. It might have a few side effects in terms of attachment keyframes... somewhat hard to track down. This method keeps everything up to date with the SkeletonData.

I think what you might be missing is that it is also generating an object in your Scene Graph in addition to generating the Controller (if it didn't already exist). SkeletonAnimation and SkeletonAnimator are generally interchangeable and both support things like SkeletonUtility.

3) Baking
This removes all dependence on the Spine API. Mesh, Skinned Mesh, and Prefab assets are generated for each Skin, AnimationClips are generated, and a RuntimeAnimationController is generated. This doesn't support all of the features present in the native Spine API however, so it has limits, but it does remove all dependence on the Spine codebase which is necessary for pushing say... an animated character into the Asset Store as the Spine runtime is not distributable to people who don't own Spine. It is also useful to simply use Spine as a rigging tool for simple things without the overhead of the full runtime.

Thanks for the speedy response


I was out Friday, but am looking at this again today.

Aha


I think I get it now. I was sort of stuck on what option #2 was actually doing, but if the Dummy object is only for timing purposes, that makes sense. Just so I get a sense of workflow, how brittle is that animator/animation set when iterating in Unity? As in, if I put some custom function call hooks within an individual animation or substates/conditionals within the animator, will that all need to be redone if I update something like an animation length in the Spine editor (requiring a rebuild from the json upon reimport)?

So far so good though, I have gotten it to work with a custom mecanim state machine, thanks again for the help!

Only the clips themselves get updated, the Graph isn't touched.

Okay, that's what I was hoping


thanks Mitch!

I've got most of it working, but I've moved onto events and had another question. It seems that the general technique for managing events is interfacing via the AnimationState, but I don't know how to query for that when using a SkeletonAnimator.

I am able to receive Spine events as Unity/mecanim style events on the mecanim timeline


though, admittedly, assuming the string name of the event as a hardcoded function call seems a little bizarre, perhaps they should at least be prefixed with "SpineEvent_" for clarity/name-collision safety? Or maybe use something more similar to the way you do your Spine attributes, with a [SpineStringEvent("EventName", "FuncMapping")] style approach?

Anyways, how would you go about getting the Complete/End generic events without AnimationState? Or, maybe a better question: how would you get the AnimationState from SkeletonAnimator?

Also


unrelated: it seems that if you have an animation without any textures in it (a guide animation), the Unity plugin will fail to produce any of the skeleton data exports from the json. Putting a junk texture in there seems to fix the problem, probably just a minor bug.

Thanks again, this has been very helpful!


Jeremy

Err I missed something in my post 🙂

Events are handled the Unity way. The dummy clips also contain AnimationEvent that are mostly equivalent to spine events. TL;DR it uses sendmessage


Anyways, how would you go about getting the Complete/End generic events without AnimationState? Or, maybe a better question: how would you get the AnimationState from SkeletonAnimator?

In unity 5 you can write graph behaviors for mecanim. Good hunting heh

AnimationState does not exist within Skeleton Animator