extends Spatial


export(NodePath) var body1
export(NodePath) var body2


func add_bound(b1: NodePath, b2: NodePath):
	var bound = Generic6DOFJoint.new()
	#bound.add_child(CSGBox.new())
	bound.set("nodes/node_a", b1)
	bound.set("nodes/node_b", b2)
	
	add_child(bound)

func _ready():
	add_bound(body1, body2)

There are two problems and one improvement in your code.

Problems)

  1. The NodePath you specify using export(NodePath) is relative to the scene, but the NodePath you give to the Joint must be an absolute path.
  2. The joint you create must be added to the node tree before it will work.

Improvement)

  1. Rather than using set, use set_node_a, set_node_b which are more appropriate.

Specifically, we will do this.

extends Spatial


export(NodePath) var body1
export(NodePath) var body2


func add_bound(b1: NodePath, b2: NodePath):
    var bound = Generic6DOFJoint.new()

    bound.set_node_a(b1)
    bound.set_node_b(b2)

    add_child(bound)


func _ready():
    add_bound(
        get_node(body1).get_path(),
        get_node(body2).get_path()
    )

Also, I think the point has to be in the position of one of the nodes before you add it to the scene. This tripped me up otherwise the rotation will be completely off.

a year later