How do I properly attach a node_b to a PinJoint2D during runtime?

Godot Version

4.7.2 Stable

Question

I’m wondering how to properly attach another physics body to a pin joint 2D during runtime. When I try to do it like how I have below, the node_b (the player in this case) doesn’t seem to be affected by any physics that the PinJoint should exert. There’s also weird behavior when I try to print out the node_b, as it prints out empty lines. I can’t see it in the output, but apparently there are messages that fill it up as indicated by the exclamation mark. Any help is greatly appreciated, thank you.

This is what the output looks like.

@onready var player : Player

func _ready() -> void:
	player = get_parent()

func _process(_delta: float) -> void:
	if is_colliding():
		var collider = get_collider()
		if collider is hookable_object:
			var pin_joint : PinJoint2D = collider.find_child("PinJoint") 
			if pin_joint:
				pin_joint.set("nodes/node_b", player.get_path()) #sets node b
				print(pin_joint.node_b)

Joint2D does not have a nodes/node_b setter so that won’t work. Assign it directly to the Joint2D.node_b property and use Node.get_path_to() instead as it needs to be relative to the Joint2D node: pin_joint.node_b = pin_joint.get_path_to(player)