Godot Version
4.4.1
Question
Hi. I was wondering if anyone could help me with an Animation/BlendTree related problem I’ve been trying to solve for a few days now. I’m trying to create an animation state machine in code i.e. without using the node editor using the .Net version of Godot 4.4.1, since the setup for each animation/transition will need to be created dynamically. I was previously adding the animations to the state machine directly and this worked without any issues, the animations were showing up in game. However, I would like to be able to control the position and scale of each animation independently, so this requires the use of individual BlendTree nodes for each animation.
I currently have an AnimationNodeStateMachine as the root of my AnimationTree, which then contains a separate AnimationNodeBlendTree for each animation state (Idle, walk etc). Now that I have added the BlendTrees, when I view the results in game the animations do not play, so I can only assume that the animation nodes need to be connected to the output of each of their BlendTrees. When I do so, I get this runtime error:
E 0:00:28:867 NativeCalls.cs:1391 @ void Godot.NativeCalls.godot_icall_3_153(nint, nint, Godot.NativeInterop.godot_string_name, int, Godot.NativeInterop.godot_string_name): Condition “!nodes.has(p_output_node)” is true.
Which refers to this line in my code:
miniBlend.ConnectNode(animName, 0, “output”);
Here is a simplified version of the method that I am using:
public AnimationTree CreateAnimationTree(Node3D bodyNode, AnimationPlayer animationPlayer, List<AnimProfile> animProfiles)
{
var animationTree = new AnimationTree
{
Name = "AnimationTree",
AnimPlayer = animationPlayer.GetPath(),
Active = true
};
var stateMachineNode = new AnimationNodeStateMachine();
animationTree.TreeRoot = stateMachineNode;
bodyNode.AddChild(animationTree);
foreach (AnimProfile profile in animProfiles)
{
string animName = profile.Key.ToString();
var miniBlend = new AnimationNodeBlendTree();
var animNode = new AnimationNodeAnimation { Animation = animName };
miniBlend.AddNode(animName, animNode, new Vector2(300, 100));
miniBlend.ConnectNode(animName, 0, "output"); // this is the line that is erroring
stateMachineNode.AddNode(animName, miniBlend, new Vector2(0, 0));
}
var playback = new AnimationNodeStateMachinePlayback();
animationTree.Set("parameters/playback", playback);
return animationTree;
}
So my question is: how do I get the animations to actually play? Is this the right way to create this kind of set up, i.e. a state machine that allows for blending transitions and lays the foundation for adding TimeScale and TimeSeek nodes for custom per-animation time scales / position seeking? Should I even be trying to connect the animations to their BlendTree outputs in this way? Is there any documentation on this at all, other than the very brief summary of each method at docs.godotengine.org?
Any help would be very much appreciated, since there doesn’t seem to be any detailed documentation on this and after eventually resorting to ChatGPT I’ve just been going round and round in circles for days.