I’m currently working on a personal project and i was wondering when should I use a State Machine or an Animation Montage.
I’m fine with working with both, I’m just not sure in which scenario I should use one over the other. From my understanding, State Machine is useful for Locomotion and Montage for attacks, etc…
Montage can easily be triggered within blueprints.
State machines require variable acquisition and additions to the animation graph to work properly.
They can both be used pretty much the same, the thing with montages is ease of use and configuration vs a specific state machine.
Take as an example a multiple animation montage.
you can concatenate several different animations into a sequence creating something you would otherwise need to create a full lenght animation for.
The other immediate benefit is the fact that a montage can be made to play on a specific chain of bones only.
Take for instance a reloading animation. You can do this action while performing almost any other movement action.
trought the slot system you can achieve this with very minimal work.
nothing keeps you from hooking an animation directly into the nodes instead of the slot, but the issue becomes “how is it triggered?”. In a best case scenario you would have to create a basic state machine and exit the animation if you enter jumping states for instance… not that it isn’t possible. Just a lot more work then 1 montage and a slot setup.
A tertiary benefit could be the elapsed time returned by the montage. It’s not as easy to get the time of the animation back to the player BP. Ofc, you would almost only need that value to code further behaviour, so you kind of need that in the character.
Pretty much any Action the player can interact with enviroment/npc is better off being a montage.
Anything the player has no real control over (movement for instance, yes you control where you go, but you don’t control How you go) is better off as a state machine.
A few things can be better off as state machines - sword combat for instance. If you start to allow for swapping weapons and you need different stances, it becomes better to use a customized state machine.
Anything requiring locomotion = state machine
Anything requiring an action = montage.
There is another option to using a state machine by keeping the locomotion states in a migration tree but for the most part you will be switching the migration pathway depending on the desired state as a reaction to the movement component as it relates to movement.
A action state is event driven as in pushing a button that can be blended as an animation layer using a per bone node. This way you can have your player swinging a sword at the same time it’s running as an example.
Since only one montage can play for a given slot you have a lot more options as to when a montage will or will not play as an event. You can also script more than a few different states with in the same montage with out the state being reset overtime the migration path switches.
Anything requiring locomotion = state machine
Anything requiring an action = montage.
And what if, for example, a player is carrying boxes? I don’t mean that he does it once in the game, but that it’s a regular mechanic, like running for example. Is it more appropriate to create a new state machine for carrying boxes or to solve it with Play Anim Montage?
OK so we need to drop further down the rabbit hole then as far as layering goes.
Locomotion would included the full body animation requirement where torso and legs needs to act together. Running for example as a locomotion = torso+legs. An action state = if the player needs to reload a weapon or push a button which would be a state independent from the legs.
Carrying boxes would be no different than say a base weapon pose but we now have a third need as far as animation migration goes in the case of context based animation, yes its a thing.
More or less a content based system could be created based on the fact that most times the state change has already occurred before the animation is even played if the full body locomotion state needs to change it;s base pose by making use of an animation tree in the locomotion position with in the migration path and not have to try and stuff a single state machine with all possible key pose changes.
Instead of a weapon how about boxes? Instead of boxes how about climbing a ladder?
These would be locomotion states based on animation context and by using a tree instead of stuffing a machine you have the ability to scale as needed as the state change requirements are already known