I have assets that I create and animate in Blender. So I want to be able to import them into Godot and have the work with AnimationTrees in a semi automated way. Meaning I don't really want to have to create the inherited scene for every asset and then add an animation tree etc etc.
The steps I have seen using the GUI are basically
- Create AnimationTree
- Create a AnimationNodeBlendTree on #1
- Configure the AnimationTree with the right AnimationPlayer
- Add a BlendSpace1D in the AnimationNodeBlendTree
- Configure that BlendSpace1D with the animations (in my case "idle" and "walk")
- Connect the BlendSpace1D to the Output
- Later update the parameters of the AnimationTree to get the blended animation
It seems like this is somewhat supported, you basically have to create an AnimationTree, AnimationNodeBlendTree, AnimationNodeBlendSpace1D and then just configure them all and then finally add the AnimationTree to the hierarchy. But it doesn't seem to work for me.
var animationTree := AnimationTree.new()
func setup_animation_tree():
var idle = self.animationPlayer.get_animation("idle")
var walking = self.animationPlayer.get_animation("walk")
var blendTree := AnimationNodeBlendTree.new()
var blendSpace := AnimationNodeBlendSpace1D.new()
var inputName = "IdleWalkInput"
blendTree.add_node(inputName, blendSpace, Vector2(100, 100))
blendTree.connect_node(inputName, 0, "Output")
self.add_child(self.animationTree)
self.animationTree.set_tree_root(blendTree)
self.animationTree.set_animation_player(self.animationPlayer.get_path())
blendSpace.min_space = 0
blendSpace.max_space = 1
blendSpace.add_blend_point(idle, 0)
blendSpace.add_blend_point(walking, 1)
Later when we want the blended animation (this examples sets the walk animation with (1):
self.animationTree.set("parameters/IdleWalkInput/blend_position", 1)
The above example assumes there is an idle and a walk animation on the model (Which I verified was the case in my test code).
My one thought here is the step where you connect the node to the output. I am really not sure if that API works at all, or is it just impossible to connect the blendspace1D to the output programmatically? It seems impossible to find the name of the Output or verify it even exists when created programmatically. So I really wonder if connect_node is working, though it does not assert.