Assigning an animationPlayer to AnimationTree via code not working?

Godot Version

4.3

Question

I have a couple of AnimationPlayer nodes that I want to dynamically add to an AnimationTree. I know the property is called anim_player and there is a setter called set_animation_player but neither seems to work.

So in the code, I tried:

animation_tree.anim_player = "skins/MainSkin/AnimationPlayer"

and

animation_tree.set_animation_player("$skins/MainSkin/AnimationPlayer")

I wasn’t sure if Godot wanted the $ before the path so I tried with and without, same result.

You need to pass an AnimationPlayer node. If you want to do it directly via the treepath this would be the way to go ($ sign, then string path):

animation_tree.anim_player = $"skins/MainSkin/AnimationPlayer"