summaryrefslogtreecommitdiffstats
path: root/scene/2d/collision_shape_2d.cpp
diff options
context:
space:
mode:
authorPedro J. Estébanez <pedrojrulez@gmail.com>2018-01-11 21:05:42 +0100
committerPedro J. Estébanez <pedrojrulez@gmail.com>2018-01-11 21:08:58 +0100
commitaefedb73fcba789207db4da0d27214eecaf0f078 (patch)
tree6e2b4faa9ac2a228019eff0c2e732395cf5413cc /scene/2d/collision_shape_2d.cpp
parenta60896869e6c17f674ff25bee87cabb54cd4403d (diff)
downloadredot-engine-aefedb73fcba789207db4da0d27214eecaf0f078.tar.gz
Update collision shapes data on tree entered
This is needed because the final startup values for shapes may change between parenting and entering the scene tree. For instance, if the collision shape belongs to a inherited scene. Fixes #13835.
Diffstat (limited to 'scene/2d/collision_shape_2d.cpp')
-rw-r--r--scene/2d/collision_shape_2d.cpp22
1 files changed, 18 insertions, 4 deletions
diff --git a/scene/2d/collision_shape_2d.cpp b/scene/2d/collision_shape_2d.cpp
index bf213614ed..0eeb6dafe5 100644
--- a/scene/2d/collision_shape_2d.cpp
+++ b/scene/2d/collision_shape_2d.cpp
@@ -45,6 +45,15 @@ void CollisionShape2D::_shape_changed() {
update();
}
+void CollisionShape2D::_update_in_shape_owner(bool p_xform_only) {
+
+ parent->shape_owner_set_transform(owner_id, get_transform());
+ if (p_xform_only)
+ return;
+ parent->shape_owner_set_disabled(owner_id, disabled);
+ parent->shape_owner_set_one_way_collision(owner_id, one_way_collision);
+}
+
void CollisionShape2D::_notification(int p_what) {
switch (p_what) {
@@ -57,9 +66,7 @@ void CollisionShape2D::_notification(int p_what) {
if (shape.is_valid()) {
parent->shape_owner_add_shape(owner_id, shape);
}
- parent->shape_owner_set_transform(owner_id, get_transform());
- parent->shape_owner_set_disabled(owner_id, disabled);
- parent->shape_owner_set_one_way_collision(owner_id, one_way_collision);
+ _update_in_shape_owner();
}
/*if (Engine::get_singleton()->is_editor_hint()) {
@@ -69,10 +76,17 @@ void CollisionShape2D::_notification(int p_what) {
}*/
} break;
+ case NOTIFICATION_ENTER_TREE: {
+
+ if (parent) {
+ _update_in_shape_owner();
+ }
+
+ } break;
case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
if (parent) {
- parent->shape_owner_set_transform(owner_id, get_transform());
+ _update_in_shape_owner(true);
}
} break;