NodePath returning wrong node

Godot Version

4.6.2

Question

Hi everyone!

I have this behavior with NodePath that I would like to understand. I have this TacticsPlanner scene that has several child actions:

Each action has a @export var action_connections: Array[Dictionary]and each entry has a Dictionarycontaining an emitter, receiver, and signal name. I’m using this data to connect signals through code.

The emitter and receiver are NodePath. When I run the TacticsPlanner code and place a for loop to connect these signals, the path seems to get the wrong node.

So, in this example, the print returns the TacticsPlanner, instead of the ComboAttackAction.

CONNECTION
TacticsPlanner:<Node#296134641754>
At: res://characters/enemy/dummy/tactics/dummy_tactics_planner.gd:15:initialize()

If I remove get_node() to check what the path being returned is, I have this:

CONNECTION
.
   At: res://characters/enemy/dummy/tactics/dummy_tactics_planner.gd:15:initialize()

I was expecting the code would return the ComboAttackAction(or any other node selected). So, why is this happening?

I see now that the NodePath reference is relative to the node where the NodePath is set. So HeavyComboActionis referencing itself, so the path is just “.”. So, if I ran the loop from TacticsActionPlanner, the script would reference itself, not the HeavyComboAction.

Any chance I can set the node from the action node instead of the planner?

Exported NodePaths are relative to the Node they are exported from. If the NodePaths are relative to the TacticsAction node then use tactic_action.get_node(connection) instead.