diff --git a/scene/2d/physics/joints/joint_2d.cpp b/scene/2d/physics/joints/joint_2d.cpp index 5f61bebbb108..c27511393efa 100644 --- a/scene/2d/physics/joints/joint_2d.cpp +++ b/scene/2d/physics/joints/joint_2d.cpp @@ -117,8 +117,12 @@ void Joint2D::_update_joint(bool p_only_free) { ba = body_a->get_rid(); bb = body_b->get_rid(); - body_a->connect(SceneStringName(tree_exiting), callable_mp(this, &Joint2D::_body_exit_tree)); - body_b->connect(SceneStringName(tree_exiting), callable_mp(this, &Joint2D::_body_exit_tree)); + if (!body_a->is_connected(SceneStringName(tree_exiting), callable_mp(this, &Joint2D::_body_exit_tree))) { + body_a->connect(SceneStringName(tree_exiting), callable_mp(this, &Joint2D::_body_exit_tree)); + } + if (!body_b->is_connected(SceneStringName(tree_exiting), callable_mp(this, &Joint2D::_body_exit_tree))) { + body_b->connect(SceneStringName(tree_exiting), callable_mp(this, &Joint2D::_body_exit_tree)); + } PhysicsServer2D::get_singleton()->joint_disable_collisions_between_bodies(joint, exclude_from_collision); } diff --git a/scene/3d/physics/joints/joint_3d.cpp b/scene/3d/physics/joints/joint_3d.cpp index dac52a4dd8c3..88ae49beaaff 100644 --- a/scene/3d/physics/joints/joint_3d.cpp +++ b/scene/3d/physics/joints/joint_3d.cpp @@ -108,12 +108,16 @@ void Joint3D::_update_joint(bool p_only_free) { if (body_a) { ba = body_a->get_rid(); - body_a->connect(SceneStringName(tree_exiting), callable_mp(this, &Joint3D::_body_exit_tree)); + if (!body_a->is_connected(SceneStringName(tree_exiting), callable_mp(this, &Joint3D::_body_exit_tree))) { + body_a->connect(SceneStringName(tree_exiting), callable_mp(this, &Joint3D::_body_exit_tree)); + } } if (body_b) { bb = body_b->get_rid(); - body_b->connect(SceneStringName(tree_exiting), callable_mp(this, &Joint3D::_body_exit_tree)); + if (!body_b->is_connected(SceneStringName(tree_exiting), callable_mp(this, &Joint3D::_body_exit_tree))) { + body_b->connect(SceneStringName(tree_exiting), callable_mp(this, &Joint3D::_body_exit_tree)); + } } PhysicsServer3D::get_singleton()->joint_disable_collisions_between_bodies(joint, exclude_from_collision);