diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2023-02-11 14:36:41 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2023-02-11 14:36:41 +0100 |
commit | 38d7583f86e9b297175137cc246f6e6369a9c210 (patch) | |
tree | bd520616931b7913c21c7e2b396611c1be18cc36 /scene/2d | |
parent | f7c177b9727895d89dbdf8e7dada2e9f53d3ee57 (diff) | |
parent | 3f31c643000c27c8dcfd5aa0977276cf613c45e1 (diff) |
Merge pull request #73063 from KoBeWi/it_exited_the_tree_but_changed_its_mind_and_broke_instead
Fix camera reparenting
Diffstat (limited to 'scene/2d')
-rw-r--r-- | scene/2d/camera_2d.cpp | 6 | ||||
-rw-r--r-- | scene/2d/camera_2d.h | 2 |
2 files changed, 8 insertions, 0 deletions
diff --git a/scene/2d/camera_2d.cpp b/scene/2d/camera_2d.cpp index fe6bee0f1b..f7d2ae7d2d 100644 --- a/scene/2d/camera_2d.cpp +++ b/scene/2d/camera_2d.cpp @@ -266,6 +266,8 @@ void Camera2D::_notification(int p_what) { clear_current(); } viewport = nullptr; + just_exited_tree = true; + callable_mp(this, &Camera2D::_reset_just_exited).call_deferred(); } break; #ifdef TOOLS_ENABLED @@ -438,6 +440,10 @@ void Camera2D::_update_process_internal_for_smoothing() { void Camera2D::make_current() { ERR_FAIL_COND(!enabled || !is_inside_tree()); get_tree()->call_group(group_name, "_make_current", this); + if (just_exited_tree) { + // If camera exited the scene tree in the same frame, group call will skip it, so this needs to be called manually. + _make_current(this); + } _update_scroll(); } diff --git a/scene/2d/camera_2d.h b/scene/2d/camera_2d.h index 7a77266db8..2417953691 100644 --- a/scene/2d/camera_2d.h +++ b/scene/2d/camera_2d.h @@ -51,6 +51,7 @@ protected: Point2 camera_pos; Point2 smoothed_camera_pos; bool first = true; + bool just_exited_tree = false; ObjectID custom_viewport_id; // to check validity Viewport *custom_viewport = nullptr; @@ -88,6 +89,7 @@ protected: void _update_scroll(); void _make_current(Object *p_which); + void _reset_just_exited() { just_exited_tree = false; } void _set_old_smoothing(real_t p_enable); |