Hello, im new here and im in sort of a pickle, cant decide and keep redoing same thing differently all over again. Ive had it.

I would like some pointers maybe from graybeards out here how you guys do this. What would be the best practice?

The problem, the struggle is not to get lost in spaghetti

For example like this:

As you can see there are too many connections between many animations and transitions.. after a break from developing, coming back to this mess just pains me to look at and think - what was this thing, what does it even do. Also when you need to debug something, remembering what kind of transition or blend conditional you have set up in UI is also a pain.

Solution i think is to use scripting. But hard coding stuff is also a pain, because what if you want to add small changes to some part of the animation process, then you have to recursively rewrite all the parts accordingly.

Now. Ive researched people making state machine where you add plain Nodes with scrip that to the transition from current anim state to new one and allows you to execute some movement logic in that state. Which seems good on paper but then you read that adding nodes to the tree is taxing on resources. Not sure if its the best idea to do that. I saw a post or video where someone did a test on empty project, added 1 000 000 empty nodes to the tree on _ready() and it dropped fps to sub 30.

What i want to achieve is something that is human readable (not long piece of code page, where you get lost in recursion etc.) -> seems like dividing the animation logic into pieces such as states -> state machine.

Also expandable, so for example i want to add new move combo or something like that -> again leaning into state machine.

Im just thinking here out loud.

So i guess my question is, Is it a good idea to use statemachine type thing for 3D animations that require blending between them for a character?

If i dont have animation tree, how to do a blending for example between idle -> walk -> run animations in code? I know how using animation tree, where you change the parameters of the blend nodes and such, but without idk. Do i need to add the animtree to node tree and add other blend nodes then change params and such via code? Or maybe there is easier solution?

    kuligs2 That "complicated" looking animation graph already is a state machine, isn't it?

      kuligs2

      how to do a blending for example between idle -> walk -> run animations in code

      You can simply use animation player with the code : animationPlayer.play("walk", 1.0) and it will blend into the "walk" animation using that number 1.0 for blending speed.

      I only use animationTree if I need to play a combined 2 or more animations (eg. lower body walking animation + upper body shooting animation)

      As for statemachine, I just use enum because it's simple and save me a lot of headaches.

        xyz Somewhat, but as i said, if you come back to it after a break from developing, atleast for me, i forget what was set and going through, clicking every connection to see how it was set, is dreadful.

        I rather read through code if you ask me.

        I think ill mock up the Node type state machine and see how it goes. Just wanted some input before i dive in. Been tinkering on my ow for far too long.

        Gowydot I only use animationTree if I need to play a combined 2 or more animations (eg. lower body walking animation + upper body shooting animation)

        I am curious, Can you not do that with code? Or how would you set up tree to have different animations playing at diff speeds?

          kuligs2 Somewhat, but as i said, if you come back to it after a break from developing

          That's why you need to learn to write documentation/notes for your project as it grows. Still easier to read documentation that to read code.

          Gowydot You can simply use animation player with the code : animationPlayer.play("walk", 1.0) and it will blend into the "walk" animation using that number 1.0 for blending speed.

          I only use animationTree if I need to play a combined 2 or more animations (eg. lower body walking animation + upper body shooting animation)

          As for statemachine, I just use enum because it's simple and save me a lot of headaches.

          Wait...now I feel stupid. I thought when I have an animation tree I have to use it to change animations and shouldn't touch the animation player at all.

          Do you by any change know how do swap out animations at runtime?
          Basically I'm looking for something like Unitys:
          AnimationOverrideController.https://docs.unity3d.com/Manual/AnimatorOverrideController.html

            trizZzle

            Yea I should have said it more clearly. I meant I'd use animationTree instead of animationPlayer if there's a combined animation.

            However, You could set animationTree inactive (in animationTree > animationMixer menu) by code anytime and just use animationPlayer. But I guess that's kinda pointless since animationTree can do anything animationPlayer can, as far as I know.

            Do you by any change know how do swap out animations at runtime?

            If I understand correctly you wanna keep the animationTree statemachine setup but just change the animation file? This seems to be the answer but I've never tried it :
            https://forum.godotengine.org/t/how-to-go-about-dynamically-changing-the-animation-in-an-animation-tree/54557

            kuligs2

            Can you not do that with code?

            You need to set up your animation logic in animationTree but you'd still use the code to "play" it.

            how would you set up tree to have different animations playing at diff speeds

            Are you talking about the blending of animations speed or the actual animation clip speed?

            For blending speed you can set it through the animationTree node menu or from the animationPlayer's play() or animationTree set() code.
            For actual clip speed there are animationPlayer's speed_scale and animationTree's TimeScale

            This looks confusing at first but animationTree is powerful and worth learning.

            Also that node-based statemachine you are trying is mainly to set up the player's states? not to be confused with the animationTree's statemachine like you shown in your first post.

              Gowydot Also that node-based statemachine you are trying is mainly to set up the player's states? not to be confused with the animationTree's statemachine like you shown in your first post.

              I guess, idk im experimenting, trying to find a best way that is not confusing. And yes i understand that the animtree statemachine is different from what im doing atm. Im trying to figure out how to tie it all in together.

              Gowydot Are you talking about the blending of animations speed or the actual animation clip speed?

              Maybe not the best words i chose, but what i wanted to ask is at different speeds more to the tone of varying animation frame rate? But this i will tackle later once i figure out how to make smooth "good feeling" anim transitions with state switching