How can I get AnimationNode that is connected to an AnimationNodeOutput

Godot Version

v4.5.1

Question

I have an AnimationNodeBlendTree object which I created programmatically, and an output node (AnimationNodeOutput object) that was created along with this AnimationNodeBlendTree object.

How do I get a node that is connected to the input of this output node, if it exists?

Use AnimationNode.get_input_name() to get the name of the AnimationNode and then AnimationNodeBlendTree.get_node() to get that AnimationNode.

AnimationNode.get_input_name() seems to return the name of input socket,

not the name of node connected to the node.

Ah, right. I didn’t test it and the documentation wasn’t clear :sweat_smile:

It’s possible to get the connections but it’s not exposed directly.

extends Node


@onready var animation_tree: AnimationTree = $AnimationTree


func _ready() -> void:
	var tree = animation_tree.tree_root as AnimationNodeBlendTree
	var connections = tree.get("node_connections")
	for i in range(0, connections.size(), 3):
		var target = connections[i + 0]
		var input_idx = connections[i + 1]
		var source = connections[i + 2]
		print("Node %s is connected to %s in port %s" % [source, target, input_idx])
1 Like

Thanks for taking the time to look into the codebase for me, It worked.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.