Best practices on using an AnimationTree StateMachine with a coded state machine

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By ipdramon

Hi everyone,

I’ve been working on my own game for quite some time with many restarts to get to know the engine. I think I figured out many great things about Godot, but one was always a bit of an eyesore to me.
When I first tried to add animations to my game I used an Animation player which worked fine. When I moved to a top-down approach like Secret of Mana I started using an AnimationTree with a state machine and sub state machines instead to make implementing view directions with my sprite easier.
As one example, I have a move state but inside it there is a walk and a run state. This works fine, but now I wanted to code more complex behavior like attacks.
Because of the bigger complexity I added a coded state machine to my project, which is called during the _process() step, but now I see that I am effectively re-implementing the state machine I create within my AnimationTree with my own coded solution.
I have seen guides on how to implement your own state machine or how to use an AnimationTree but not both combined.
Therefore I ask whether there are any best practices on this topic.
I know there may not be a best solution on this, but any idea is appreciated.

:bust_in_silhouette: Reply From: Ertain

What I’ve done is try to have one animation for each state. So if the character has a “walk” state, that will have an accompanying “walk” animation. If a group of animations are a part of a mechanic, I try to have those put together in one of the nodes of an AnimationTree, and have the state control that group. I use a decent number of signals to keep these synchronized, where the AnimationTree may have a script which checks for a certain state, and then handles the animation (or its properties) related to that state.

Hope this helps.

Yeah, that sounds like what I am currently doing. I normally try to not implement the same ideas in two places (AnimationTree and code here), but it seems that it is impossible here. The one thing I find most exhausting is the need to implement the edges according to my states and animations in the AnimationTree. Do you just replicate the state machines structure in the AnimationTree as well?

ipdramon | 2022-11-29 18:50