Hi guys,
I've been away for a while. ;)

I'm considering starting a new combat system involving mainly combo attacks.

A simple way to do that seems like a state machine, so you can check if which attack mode you are (punch, kicks whatever) and during attack number "x" you can transitate to attack number x+1 when you get the button input.

Hardcoding this is certainly doable but seems like a fair amount of work and organization, so I was wondering if there is already a "go to way" of using Mecanim as a logic state machine that could communicate with skeletonAnmation (I'm not talking about skeletonAnimator). :)

I remember that someone did something like this few years ago, but haven't been able to find it back.
Also maybe today it wouldn't be up to date.

So are there any of you guys that already uses such a method and are there pros and cons that I should be aware of ?

Thank you all,
  • Posts: 147


We don't have a "go-to" way, but I just updated the example scene on git that sort of does this.

The example just has a thin StateMachineBehaviour on the state machine (not any specific state). All it does is send the state name hash to a component on the GameObject whenever the state changes. This assumes using Mecanim as a finite state machine so the ideal setup is 0 transition times on this end. That doesn't mean 0 animation transitions. It just means the game logic for states doesn't involve being in-between states.

The component on the GameObject serves as an intermediary "animation handle" so that the StateMachineBehaviour doesn't need to know anything about SkeletonAnimation. In the example, it stores which Animation should play for each state. As a bonus, it stores which transitions animations should be played based on the current animation and target animation.

This example, if you expound on it, does involve the extra work organizing things (but it's sort of the typical price for separating game logic from animation). Some extra inspector tools and pretty property drawers and maybe custom ScriptableObjects will probably help make organization a bit easier.
User avatar
  • Posts: 5366


Hi Pharan, thank you for the exemple scene, it does clarify things, a lot !

Right now I'm trying to wrap my head around how to build on that to have a fairly complex and extendable animation/combat system including interruptions and combos.
I'll let you know about my progress.

Thanks again :)
  • Posts: 147

Return to Unity