How to go about dynamically changing the animation in an animation tree?

Godot Version

4.2.1

Question

I’m currently working on the animation system for my game and there are a bunch of animations that will play depending on the kind of weapon used and actions taken etc. I’ve run into a problem though and that’s that there doesn’t seem to be a way to change the animation node in the animation tree at runtime.

godotAnimTrouble

What I want to do:
There are many different kind of weapons and abilities in the game. When the player switches ability I want to be able to load that animation resource and swap the AnimationNode parameter with the new one before playing the one shot.

I’ve done some searching but there doesn’t seem to be a way to do this? I could make a huge state machine but with over an estimated >100 animations that doesn’t feel like it’s the intended way.

How do other people takle this problem?

Thank you,

Thank you for your answer, however the problem is that the animation node properties are not exposed like the other ones and the docs doesn’t shine light on how to solve the problem.

I did find a way to access the node properties directly though. With this code:

tree_root.get_node("AnimatioNodeName").animation = "new_animation_name"

This solves the problem of changing the animation but it feels like a hack solution. Is there a reason why the animation node properties are not exposed? This have been the case for quite a few years from my understanding, having read a number of threads in different places.

The same goes for changing the animations in a blend space node, I’ll have to find a way to change those manually, if it’s possible. (I would need to find a way to access the points in the blend space)

One thing that would make the animation tree much more flexible is to make the actual animations used in the tree exposed as a variable that can be changed if needed. Especially when you have a layout that is identical between sets of animations.

Ok, so just a few moments later I found it, haha:

Edit: here are the nodes needed to change the animation node and blendspace

AnimationNode
tree_root.get_node("AnimatioNodeName").animation = "new_animation_name"

Blendspace Points
tree_root.get_node("BlendName").get_blend_point_node(index).animation = "new_animation"

Still, it required a bit of digging down a few layers of the animation tree class reference doc. Now I can switch those values on the fly when I change between weapon types. Hooray!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.