summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2020-05-11 10:27:42 +0200
committerGitHub <noreply@github.com>2020-05-11 10:27:42 +0200
commit22db30100946678175f188de58a413749256e028 (patch)
tree2bca022783e8dc5af46001cbe5fd39e064e7a3c2
parentdbd90b9478f4243bc0ed46527afcd6be78279266 (diff)
parentd0c5d91032faae9efec028db7b07c1ba79d6d6ea (diff)
Merge pull request #31938 from KoBeWi/a_welcome_lag
Fix VisibilityEnabler2D behavior on start
-rw-r--r--scene/2d/visibility_notifier_2d.cpp17
1 files changed, 13 insertions, 4 deletions
diff --git a/scene/2d/visibility_notifier_2d.cpp b/scene/2d/visibility_notifier_2d.cpp
index c374dd5faa..780d08693d 100644
--- a/scene/2d/visibility_notifier_2d.cpp
+++ b/scene/2d/visibility_notifier_2d.cpp
@@ -248,10 +248,19 @@ void VisibilityEnabler2D::_notification(int p_what) {
_find_nodes(from);
- if (enabler[ENABLER_PARENT_PHYSICS_PROCESS] && get_parent())
- get_parent()->set_physics_process(false);
- if (enabler[ENABLER_PARENT_PROCESS] && get_parent())
- get_parent()->set_process(false);
+ // We need to defer the call of set_process and set_physics_process,
+ // otherwise they are overwritten inside NOTIFICATION_READY.
+ // We can't use call_deferred, because it happens after a physics frame.
+ // The ready signal works as it's emitted immediately after NOTIFICATION_READY.
+
+ if (enabler[ENABLER_PARENT_PHYSICS_PROCESS] && get_parent()) {
+ get_parent()->connect(SceneStringNames::get_singleton()->ready,
+ callable_mp(get_parent(), &Node::set_physics_process), varray(false), CONNECT_ONESHOT);
+ }
+ if (enabler[ENABLER_PARENT_PROCESS] && get_parent()) {
+ get_parent()->connect(SceneStringNames::get_singleton()->ready,
+ callable_mp(get_parent(), &Node::set_process), varray(false), CONNECT_ONESHOT);
+ }
}
if (p_what == NOTIFICATION_EXIT_TREE) {