• Unity
  • SkeletonGraphic + Animation Controller

Related Discussions
...

Hi, I need to use Spine animations inside a Canvas, for that I'm using SkeletonGraphic. How do I use an animation controller with this setup?

Thanks!

That's what I thought, thanks for the confirmation.
So, I guess my best option would be to use StateMachineBehaviour, right?

Thanks a lot.

Yes, this will be your best option if you have to use Canvas and Mecanim. I assume you have already seen the example scene Spine Examples/Other Examples/Mecanim Logic SkeletonAnimation View where this is demonstrated, right?

I've seen it, I have already implemented it and it's working fine.

After I implemented this though, I learned that animations can be baked into Unity animation clips. That looks like a much more cleaner way to do it.
I know that not every feature of Spine's animation system are supported, but besides that, I wonder if there are any other drawbacks to this approach. For instance, would the performance for baked animations be worse?

Thanks a lot for your help.

Luckily the baking feature has just recently been re-activated for newer Unity versions as well, so this is now again also an option. 🙂

Performance wise, the baked clips might even yield slightly better performance (depending on your skeleton setup), but there are some major drawbacks that are important to know:

  • Only a subset of Spine's functionality is baked to clips.
  • Animated Attachment visibility will be e bit off sometimes. E.g. in Raptor's gungrab animation, the gun will shortly be shown twice - the version with the hand will be shown at the same time as the gun-nohand attachment.
  • Additional animation layers might not add up as expected (as previewed in the Spine Editor).
  • Constraints are baked as is, so e.g. a aim-at-target constraint (as shown in the 4 Object Oriented Sample scene) can no longer be modified at runtime.
  • There will be a lot of additional keyframes for each animation, creating additional data. This is because not only the keyframes set by the user will be present, but instead every bake-increment of 1/60 second, there will be a keyframe (to prevent interpolation differences).

So in short: it is not really a clean solution to use the baked clips, uncless you use only a small subset of Spine's functionality. We would recommend baked clips only as a last resort. The StateMachineBehaviour would most likely be the preferred solution in your case.

10 dana kasnije

It's almost working using the StateMachineBehaviour approach, but one major problem is that if you set transitions to use the "Has Exit Time" option, then all states play for the same period of time, regardless of the animation clip duration.
This problem is also present in the example "Mecanim Logic SkeletonAnimation View" if you set any transition to use that option.

Is there a way to solve this?

Thanks a lot for your help.

You can use the respective animation clip which is generated for the SkeletonMecanim component and assign it at the target state. It will then pick the duration of your assigned clip.

  1. First generate the assets from the SkeletonDataAsset Inspector via SkeletonMecanim - Generate Mecanim Controller as shown here.

  2. Then assign the generated animation clip to the state.

    Image removed due to the lack of support for HTTPS. | Show Anyway