Merge pull request #46579 from nekomatata/fix-joint-remove-body-regression-3.2
[3.2] Fix Joint2D/Joint node path reset on scene switch
This commit is contained in:
commit
c003423674
4 changed files with 12 additions and 28 deletions
|
@ -48,18 +48,10 @@ void Joint2D::_disconnect_signals() {
|
||||||
body_b->disconnect(SceneStringNames::get_singleton()->tree_exiting, this, SceneStringNames::get_singleton()->_body_exit_tree);
|
body_b->disconnect(SceneStringNames::get_singleton()->tree_exiting, this, SceneStringNames::get_singleton()->_body_exit_tree);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Joint2D::_body_exit_tree(const ObjectID &p_body_id) {
|
void Joint2D::_body_exit_tree() {
|
||||||
|
|
||||||
_disconnect_signals();
|
_disconnect_signals();
|
||||||
Object *object = ObjectDB::get_instance(p_body_id);
|
_update_joint(true);
|
||||||
PhysicsBody2D *body = Object::cast_to<PhysicsBody2D>(object);
|
|
||||||
ERR_FAIL_NULL(body);
|
|
||||||
RID body_rid = body->get_rid();
|
|
||||||
if (ba == body_rid)
|
|
||||||
a = NodePath();
|
|
||||||
if (bb == body_rid)
|
|
||||||
b = NodePath();
|
|
||||||
_update_joint();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Joint2D::_update_joint(bool p_only_free) {
|
void Joint2D::_update_joint(bool p_only_free) {
|
||||||
|
@ -135,8 +127,8 @@ void Joint2D::_update_joint(bool p_only_free) {
|
||||||
ba = body_a->get_rid();
|
ba = body_a->get_rid();
|
||||||
bb = body_b->get_rid();
|
bb = body_b->get_rid();
|
||||||
|
|
||||||
body_a->connect(SceneStringNames::get_singleton()->tree_exiting, this, SceneStringNames::get_singleton()->_body_exit_tree, make_binds(body_a->get_instance_id()));
|
body_a->connect(SceneStringNames::get_singleton()->tree_exiting, this, SceneStringNames::get_singleton()->_body_exit_tree);
|
||||||
body_b->connect(SceneStringNames::get_singleton()->tree_exiting, this, SceneStringNames::get_singleton()->_body_exit_tree, make_binds(body_b->get_instance_id()));
|
body_b->connect(SceneStringNames::get_singleton()->tree_exiting, this, SceneStringNames::get_singleton()->_body_exit_tree);
|
||||||
|
|
||||||
Physics2DServer::get_singleton()->joint_disable_collisions_between_bodies(joint, exclude_from_collision);
|
Physics2DServer::get_singleton()->joint_disable_collisions_between_bodies(joint, exclude_from_collision);
|
||||||
}
|
}
|
||||||
|
@ -233,7 +225,7 @@ String Joint2D::get_configuration_warning() const {
|
||||||
|
|
||||||
void Joint2D::_bind_methods() {
|
void Joint2D::_bind_methods() {
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("_body_exit_tree", "body_rid"), &Joint2D::_body_exit_tree);
|
ClassDB::bind_method(D_METHOD("_body_exit_tree"), &Joint2D::_body_exit_tree);
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("set_node_a", "node"), &Joint2D::set_node_a);
|
ClassDB::bind_method(D_METHOD("set_node_a", "node"), &Joint2D::set_node_a);
|
||||||
ClassDB::bind_method(D_METHOD("get_node_a"), &Joint2D::get_node_a);
|
ClassDB::bind_method(D_METHOD("get_node_a"), &Joint2D::get_node_a);
|
||||||
|
|
|
@ -51,7 +51,7 @@ class Joint2D : public Node2D {
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void _disconnect_signals();
|
void _disconnect_signals();
|
||||||
void _body_exit_tree(const ObjectID &p_body_id);
|
void _body_exit_tree();
|
||||||
void _update_joint(bool p_only_free = false);
|
void _update_joint(bool p_only_free = false);
|
||||||
|
|
||||||
void _notification(int p_what);
|
void _notification(int p_what);
|
||||||
|
|
|
@ -45,18 +45,10 @@ void Joint::_disconnect_signals() {
|
||||||
body_b->disconnect(SceneStringNames::get_singleton()->tree_exiting, this, SceneStringNames::get_singleton()->_body_exit_tree);
|
body_b->disconnect(SceneStringNames::get_singleton()->tree_exiting, this, SceneStringNames::get_singleton()->_body_exit_tree);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Joint::_body_exit_tree(const ObjectID &p_body_id) {
|
void Joint::_body_exit_tree() {
|
||||||
|
|
||||||
_disconnect_signals();
|
_disconnect_signals();
|
||||||
Object *object = ObjectDB::get_instance(p_body_id);
|
_update_joint(true);
|
||||||
PhysicsBody *body = Object::cast_to<PhysicsBody>(object);
|
|
||||||
ERR_FAIL_NULL(body);
|
|
||||||
RID body_rid = body->get_rid();
|
|
||||||
if (ba == body_rid)
|
|
||||||
a = NodePath();
|
|
||||||
if (bb == body_rid)
|
|
||||||
b = NodePath();
|
|
||||||
_update_joint();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Joint::_update_joint(bool p_only_free) {
|
void Joint::_update_joint(bool p_only_free) {
|
||||||
|
@ -128,12 +120,12 @@ void Joint::_update_joint(bool p_only_free) {
|
||||||
|
|
||||||
if (body_a) {
|
if (body_a) {
|
||||||
ba = body_a->get_rid();
|
ba = body_a->get_rid();
|
||||||
body_a->connect(SceneStringNames::get_singleton()->tree_exiting, this, SceneStringNames::get_singleton()->_body_exit_tree, make_binds(body_a->get_instance_id()));
|
body_a->connect(SceneStringNames::get_singleton()->tree_exiting, this, SceneStringNames::get_singleton()->_body_exit_tree);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (body_b) {
|
if (body_b) {
|
||||||
bb = body_b->get_rid();
|
bb = body_b->get_rid();
|
||||||
body_b->connect(SceneStringNames::get_singleton()->tree_exiting, this, SceneStringNames::get_singleton()->_body_exit_tree, make_binds(body_b->get_instance_id()));
|
body_b->connect(SceneStringNames::get_singleton()->tree_exiting, this, SceneStringNames::get_singleton()->_body_exit_tree);
|
||||||
}
|
}
|
||||||
|
|
||||||
PhysicsServer::get_singleton()->joint_disable_collisions_between_bodies(joint, exclude_from_collision);
|
PhysicsServer::get_singleton()->joint_disable_collisions_between_bodies(joint, exclude_from_collision);
|
||||||
|
@ -230,7 +222,7 @@ String Joint::get_configuration_warning() const {
|
||||||
|
|
||||||
void Joint::_bind_methods() {
|
void Joint::_bind_methods() {
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("_body_exit_tree", "body_rid"), &Joint::_body_exit_tree);
|
ClassDB::bind_method(D_METHOD("_body_exit_tree"), &Joint::_body_exit_tree);
|
||||||
|
|
||||||
ClassDB::bind_method(D_METHOD("set_node_a", "node"), &Joint::set_node_a);
|
ClassDB::bind_method(D_METHOD("set_node_a", "node"), &Joint::set_node_a);
|
||||||
ClassDB::bind_method(D_METHOD("get_node_a"), &Joint::get_node_a);
|
ClassDB::bind_method(D_METHOD("get_node_a"), &Joint::get_node_a);
|
||||||
|
|
|
@ -51,7 +51,7 @@ class Joint : public Spatial {
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void _disconnect_signals();
|
void _disconnect_signals();
|
||||||
void _body_exit_tree(const ObjectID &p_body_id);
|
void _body_exit_tree();
|
||||||
void _update_joint(bool p_only_free = false);
|
void _update_joint(bool p_only_free = false);
|
||||||
|
|
||||||
void _notification(int p_what);
|
void _notification(int p_what);
|
||||||
|
|
Loading…
Reference in a new issue