I want to swap out the animation I am using in one node(animationtree node) so that I can change between them without having to set up something crazy...that I don't think Godot can even do...

I know this is wrong but it's my intention to swap out that sword attack with other animations

anim_tree.set("parameters/attack_anim/animation/sword_hack_L","sword_slash_L")

So, I have an animation tree....

Any advice? I already have a thread about this, but have not received any answers and it's turing into a back and forth conversation, which I want to avoid making a long thread...because if another new user does a search they will have to filter through a lot of discussion, instead of a straight solution.

So, any ideas?

I figured this out. In case anyone has the same issue I will try to pass on what I've done to get it to work.

1) instead of using an animation node, use a blend space 2D

2) you need to edit the blendspace and add your animations, there is simply not enough space here for me to show how to do all of that so, try to check on youtube or around the forums.

3) use this code to select the proper animation.

# the vector would be the specific coordinates of where you placed your node in the blend space
AnimTree.set("parameters/blendspace2d name/blend_position",Vector2(0,1))
#for clarity 'blendspace2d name' it the name you typed into the name field in the animation node editor
# same for the next step with 'oneshot name' replace that with whatever you've named your OneShot.

4) enable the one shot node.

AnimationTree.set("parameters/oneshot name/active",true)

I hope someone finds this helpful, it was a real headache trying to figure it out.

Glad to hear you found a solution eventually. Sorry I didn't know more about animations or I would have tried to help.

3 months later

This is an old, or at least an old-ish topic, but I'd still like to add my 2 cents in case it'll be useful for someone in the future.

To set the animation you need to access the AnimationNodeAnimation. You can find it through the TreeRoot. If you use, for instance, the AnimationNodeBlendTree as the root in your AnimationTree, then you just use GetNode to get the AnimationNodeAnimation that is used to select an animation with SetAnimation.

In C# it'll look something like this (assuming you're using a blend tree as the tree root):

// Get the node from the scene AnimationTree animTree = (AnimationTree)FindNode("your_anim_tree_name");

// Get the tree root using the correct type AnimationNodeBlendTree animTreeRoot = (AnimationNodeBlendTree)animTree.TreeRoot;

// Find the animation node from the tree AnimationNodeAnimation animNode = (AnimationNodeAnimation)animTreeRoot.GetNode("your_animation_node_name_inside_your_blend_tree");

// Set the animation animNode.SetAnimation("some animation");

So if I have a blendtree and inside it an animation node called "Animation_Upperbody_Idle", I'd use that as the ID in my animTreeRoot.GetNode-call.

If you plan to use the scene you're animating as a template to, say, instantiate a lot of baddies who all run a different animation at any one time, don't forget to check the "Local to Scene" checkbox for your animation tree nodes. If a node is not local to scene, all the instantiated nodes will share the same node. What this means is that if the "Local to Scene" is not checked on your animation node, when you change the animation to one baddie, you change it for every one of them.

a year later

I found this post when trying to work out how to trigger a one-handed or two-handed attack, and while I didn't use the exact solution, it did inspire me to create this solution:

Basically, instead of swapping out the animation using a blend node, I use a transition node that I simply switch when I attack... this way I could easily add more attack options in the future. The surrounding IF simply stops me from being able to spam alternating attacks - it has to have completed the one shot before it allows you to attack again.

a year later

this works for me with Animation Node State Machine:

# "walk_right" is the name of an state in the $AnimationTree
# "sword_walk_right" and "hammer_walk_right" are nodes in the $AnimationPlayer

print(AnimationTree.get_tree_root().get_node("walk_right").animation) # sword_walk_right

$AnimationTree.get_tree_root().get_node("walk_right").animation = "hammer_walk_right" #make the change

print(AnimationTree.get_tree_root().get_node("walk_right").animation) # hammer_walk_right
10 months later