Integrating BlendSpace2D resources with my node-based state machine

Godot Version

4.7.stable

Question

So I’ve been dabbling in “composition over inheritance” and creating more modular systems in general, and in my testing I’ve run into a problem I’m not quite sure how to solve.

What I’d like to do is @export a BlendSpace2D resource for each state in my node-based state machine (pull) and then have my state machine pass the BlendSpace2D to an AnimationTree or something to play it.

Is this something I can do? I know I can use an AnimationTree for state machine stuff, but since I’m already writing the code for this node-based state machine, this just feels to me like the most intuitive way to go about this. It just seems like it would save me a lot of time and setup if I could do it with code and resources alone, but I’m too new to godot to know if this is A) Possible, or B) A good idea.

Is it possible? Yes. Is it a good idea? in my opinion, no.

You can @export any Resource. AnimationNodeBlendSpace2D is a Resource. So, technically yes, you can @export it but only the AnimationTree node is able to edit and work with AnimationNode resources.

Also, AnimationNode resources by themselves do nothing. The AnimationTree node is the one in charge of orchestrating them so you’d still need to have the AnimationTree node with some AnimationTree.tree_root AnimationNodeRoot that you’d need to modify by adding/removing the blend spaces and interacting with them.

Couldn’t I just AnimationTree.tree_root = blend_space? If that actually works, I don’t understand why it’s a bad idea. It seems to me like it would beat having to set up all the state switching in the AnimationTree. I mean I already have to code the state switches anyway so what’s 1 more line in my state machine to set tree_root?

You’ll need to blend from one blend space to another and changing the AnimationTree.tree_root won’t apply any blending between them.