diff --git a/doc/classes/Node.xml b/doc/classes/Node.xml index d16a128034d..d0c948e599b 100644 --- a/doc/classes/Node.xml +++ b/doc/classes/Node.xml @@ -32,8 +32,8 @@ - Called when the node leaves the [SceneTree] (e.g. upon freeing, scene changing, or after calling [method remove_child] in a script). If the node has children, its [method _exit_tree] callback will be called last, after all its children have left the tree. - Corresponds to the NOTIFICATION_EXIT_TREE notification in [method Object._notification]. + Called when the node is about to leave the [SceneTree] (e.g. upon freeing, scene changing, or after calling [method remove_child] in a script). If the node has children, its [method _exit_tree] callback will be called last, after all its children have left the tree. + Corresponds to the NOTIFICATION_EXIT_TREE notification in [method Object._notification] and signal [signal tree_exiting]. To get notified when the node has already left the active tree, connect to the [signal tree_exited] @@ -744,9 +744,14 @@ Emitted when the node enters the tree. + + + Emitted when the node is still active but about to exit the tree. This is the right place for de-initialization. + + - Emitted when the node exits the tree. + Emitted after the node exits the tree and is no longer active. @@ -755,7 +760,7 @@ Notification received when the node enters a [SceneTree]. - Notification received when the node exits a [SceneTree]. + Notification received when the node is about to exit a [SceneTree]. Notification received when the node is moved in the parent. diff --git a/editor/animation_editor.cpp b/editor/animation_editor.cpp index 7e49d1300c7..91aa189c8fa 100644 --- a/editor/animation_editor.cpp +++ b/editor/animation_editor.cpp @@ -3119,12 +3119,12 @@ void AnimationKeyEditor::set_animation(const Ref &p_anim) { void AnimationKeyEditor::set_root(Node *p_root) { if (root) - root->disconnect("tree_exited", this, "_root_removed"); + root->disconnect("tree_exiting", this, "_root_removed"); root = p_root; if (root) - root->connect("tree_exited", this, "_root_removed", make_binds(), CONNECT_ONESHOT); + root->connect("tree_exiting", this, "_root_removed", make_binds(), CONNECT_ONESHOT); } Node *AnimationKeyEditor::get_root() const { diff --git a/editor/editor_data.cpp b/editor/editor_data.cpp index 374688f2dbb..95ed40d889b 100644 --- a/editor/editor_data.cpp +++ b/editor/editor_data.cpp @@ -829,7 +829,7 @@ void EditorSelection::add_node(Node *p_node) { } selection[p_node] = meta; - p_node->connect("tree_exited", this, "_node_removed", varray(p_node), CONNECT_ONESHOT); + p_node->connect("tree_exiting", this, "_node_removed", varray(p_node), CONNECT_ONESHOT); //emit_signal("selection_changed"); } @@ -847,7 +847,7 @@ void EditorSelection::remove_node(Node *p_node) { if (meta) memdelete(meta); selection.erase(p_node); - p_node->disconnect("tree_exited", this, "_node_removed"); + p_node->disconnect("tree_exiting", this, "_node_removed"); //emit_signal("selection_changed"); } bool EditorSelection::is_selected(Node *p_node) const { diff --git a/editor/plugins/spatial_editor_plugin.cpp b/editor/plugins/spatial_editor_plugin.cpp index b677017371e..cef1da1d06d 100644 --- a/editor/plugins/spatial_editor_plugin.cpp +++ b/editor/plugins/spatial_editor_plugin.cpp @@ -2689,7 +2689,7 @@ void SpatialEditorViewport::_toggle_camera_preview(bool p_activate) { if (!p_activate) { - previewing->disconnect("tree_exited", this, "_preview_exited_scene"); + previewing->disconnect("tree_exiting", this, "_preview_exited_scene"); previewing = NULL; VS::get_singleton()->viewport_attach_camera(viewport->get_viewport_rid(), camera->get_camera()); //restore if (!preview) @@ -2700,7 +2700,7 @@ void SpatialEditorViewport::_toggle_camera_preview(bool p_activate) { } else { previewing = preview; - previewing->connect("tree_exited", this, "_preview_exited_scene"); + previewing->connect("tree_exiting", this, "_preview_exited_scene"); VS::get_singleton()->viewport_attach_camera(viewport->get_viewport_rid(), preview->get_camera()); //replace view_menu->hide(); surface->update(); @@ -2851,7 +2851,7 @@ void SpatialEditorViewport::set_state(const Dictionary &p_state) { Node *pv = EditorNode::get_singleton()->get_edited_scene()->get_node(p_state["previewing"]); if (Object::cast_to(pv)) { previewing = Object::cast_to(pv); - previewing->connect("tree_exited", this, "_preview_exited_scene"); + previewing->connect("tree_exiting", this, "_preview_exited_scene"); VS::get_singleton()->viewport_attach_camera(viewport->get_viewport_rid(), previewing->get_camera()); //replace view_menu->hide(); surface->update(); diff --git a/scene/2d/area_2d.cpp b/scene/2d/area_2d.cpp index 6ecf661efd6..6fff7ac0a48 100644 --- a/scene/2d/area_2d.cpp +++ b/scene/2d/area_2d.cpp @@ -170,7 +170,7 @@ void Area2D::_body_inout(int p_status, const RID &p_body, int p_instance, int p_ E->get().in_tree = node && node->is_inside_tree(); if (node) { node->connect(SceneStringNames::get_singleton()->tree_entered, this, SceneStringNames::get_singleton()->_body_enter_tree, make_binds(objid)); - node->connect(SceneStringNames::get_singleton()->tree_exited, this, SceneStringNames::get_singleton()->_body_exit_tree, make_binds(objid)); + node->connect(SceneStringNames::get_singleton()->tree_exiting, this, SceneStringNames::get_singleton()->_body_exit_tree, make_binds(objid)); if (E->get().in_tree) { emit_signal(SceneStringNames::get_singleton()->body_entered, node); } @@ -197,7 +197,7 @@ void Area2D::_body_inout(int p_status, const RID &p_body, int p_instance, int p_ if (node) { node->disconnect(SceneStringNames::get_singleton()->tree_entered, this, SceneStringNames::get_singleton()->_body_enter_tree); - node->disconnect(SceneStringNames::get_singleton()->tree_exited, this, SceneStringNames::get_singleton()->_body_exit_tree); + node->disconnect(SceneStringNames::get_singleton()->tree_exiting, this, SceneStringNames::get_singleton()->_body_exit_tree); if (E->get().in_tree) emit_signal(SceneStringNames::get_singleton()->body_exited, obj); } @@ -271,7 +271,7 @@ void Area2D::_area_inout(int p_status, const RID &p_area, int p_instance, int p_ E->get().in_tree = node && node->is_inside_tree(); if (node) { node->connect(SceneStringNames::get_singleton()->tree_entered, this, SceneStringNames::get_singleton()->_area_enter_tree, make_binds(objid)); - node->connect(SceneStringNames::get_singleton()->tree_exited, this, SceneStringNames::get_singleton()->_area_exit_tree, make_binds(objid)); + node->connect(SceneStringNames::get_singleton()->tree_exiting, this, SceneStringNames::get_singleton()->_area_exit_tree, make_binds(objid)); if (E->get().in_tree) { emit_signal(SceneStringNames::get_singleton()->area_entered, node); } @@ -298,7 +298,7 @@ void Area2D::_area_inout(int p_status, const RID &p_area, int p_instance, int p_ if (node) { node->disconnect(SceneStringNames::get_singleton()->tree_entered, this, SceneStringNames::get_singleton()->_area_enter_tree); - node->disconnect(SceneStringNames::get_singleton()->tree_exited, this, SceneStringNames::get_singleton()->_area_exit_tree); + node->disconnect(SceneStringNames::get_singleton()->tree_exiting, this, SceneStringNames::get_singleton()->_area_exit_tree); if (E->get().in_tree) emit_signal(SceneStringNames::get_singleton()->area_exited, obj); } @@ -338,7 +338,7 @@ void Area2D::_clear_monitoring() { //ERR_CONTINUE(!node); node->disconnect(SceneStringNames::get_singleton()->tree_entered, this, SceneStringNames::get_singleton()->_body_enter_tree); - node->disconnect(SceneStringNames::get_singleton()->tree_exited, this, SceneStringNames::get_singleton()->_body_exit_tree); + node->disconnect(SceneStringNames::get_singleton()->tree_exiting, this, SceneStringNames::get_singleton()->_body_exit_tree); if (!E->get().in_tree) continue; @@ -368,7 +368,7 @@ void Area2D::_clear_monitoring() { //ERR_CONTINUE(!node); node->disconnect(SceneStringNames::get_singleton()->tree_entered, this, SceneStringNames::get_singleton()->_area_enter_tree); - node->disconnect(SceneStringNames::get_singleton()->tree_exited, this, SceneStringNames::get_singleton()->_area_exit_tree); + node->disconnect(SceneStringNames::get_singleton()->tree_exiting, this, SceneStringNames::get_singleton()->_area_exit_tree); if (!E->get().in_tree) continue; diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp index 7f96a258e02..1b25b3588ad 100644 --- a/scene/2d/physics_body_2d.cpp +++ b/scene/2d/physics_body_2d.cpp @@ -310,7 +310,7 @@ void RigidBody2D::_body_inout(int p_status, ObjectID p_instance, int p_body_shap E->get().in_scene = node && node->is_inside_tree(); if (node) { node->connect(SceneStringNames::get_singleton()->tree_entered, this, SceneStringNames::get_singleton()->_body_enter_tree, make_binds(objid)); - node->connect(SceneStringNames::get_singleton()->tree_exited, this, SceneStringNames::get_singleton()->_body_exit_tree, make_binds(objid)); + node->connect(SceneStringNames::get_singleton()->tree_exiting, this, SceneStringNames::get_singleton()->_body_exit_tree, make_binds(objid)); if (E->get().in_scene) { emit_signal(SceneStringNames::get_singleton()->body_entered, node); } @@ -339,7 +339,7 @@ void RigidBody2D::_body_inout(int p_status, ObjectID p_instance, int p_body_shap if (node) { node->disconnect(SceneStringNames::get_singleton()->tree_entered, this, SceneStringNames::get_singleton()->_body_enter_tree); - node->disconnect(SceneStringNames::get_singleton()->tree_exited, this, SceneStringNames::get_singleton()->_body_exit_tree); + node->disconnect(SceneStringNames::get_singleton()->tree_exiting, this, SceneStringNames::get_singleton()->_body_exit_tree); if (in_scene) emit_signal(SceneStringNames::get_singleton()->body_exited, obj); } diff --git a/scene/2d/visibility_notifier_2d.cpp b/scene/2d/visibility_notifier_2d.cpp index c2227d99643..4b38534d971 100644 --- a/scene/2d/visibility_notifier_2d.cpp +++ b/scene/2d/visibility_notifier_2d.cpp @@ -219,7 +219,7 @@ void VisibilityEnabler2D::_find_nodes(Node *p_node) { if (add) { - p_node->connect(SceneStringNames::get_singleton()->tree_exited, this, "_node_removed", varray(p_node), CONNECT_ONESHOT); + p_node->connect(SceneStringNames::get_singleton()->tree_exiting, this, "_node_removed", varray(p_node), CONNECT_ONESHOT); nodes[p_node] = meta; _change_node_state(p_node, false); } @@ -262,7 +262,7 @@ void VisibilityEnabler2D::_notification(int p_what) { if (!visible) _change_node_state(E->key(), true); - E->key()->disconnect(SceneStringNames::get_singleton()->tree_exited, this, "_node_removed"); + E->key()->disconnect(SceneStringNames::get_singleton()->tree_exiting, this, "_node_removed"); } nodes.clear(); diff --git a/scene/3d/area.cpp b/scene/3d/area.cpp index 4089d80d4e5..21f471039f1 100644 --- a/scene/3d/area.cpp +++ b/scene/3d/area.cpp @@ -169,7 +169,7 @@ void Area::_body_inout(int p_status, const RID &p_body, int p_instance, int p_bo E->get().in_tree = node && node->is_inside_tree(); if (node) { node->connect(SceneStringNames::get_singleton()->tree_entered, this, SceneStringNames::get_singleton()->_body_enter_tree, make_binds(objid)); - node->connect(SceneStringNames::get_singleton()->tree_exited, this, SceneStringNames::get_singleton()->_body_exit_tree, make_binds(objid)); + node->connect(SceneStringNames::get_singleton()->tree_exiting, this, SceneStringNames::get_singleton()->_body_exit_tree, make_binds(objid)); if (E->get().in_tree) { emit_signal(SceneStringNames::get_singleton()->body_entered, node); } @@ -196,7 +196,7 @@ void Area::_body_inout(int p_status, const RID &p_body, int p_instance, int p_bo if (node) { node->disconnect(SceneStringNames::get_singleton()->tree_entered, this, SceneStringNames::get_singleton()->_body_enter_tree); - node->disconnect(SceneStringNames::get_singleton()->tree_exited, this, SceneStringNames::get_singleton()->_body_exit_tree); + node->disconnect(SceneStringNames::get_singleton()->tree_exiting, this, SceneStringNames::get_singleton()->_body_exit_tree); if (E->get().in_tree) emit_signal(SceneStringNames::get_singleton()->body_exited, obj); } @@ -246,7 +246,7 @@ void Area::_clear_monitoring() { emit_signal(SceneStringNames::get_singleton()->body_exited, obj); node->disconnect(SceneStringNames::get_singleton()->tree_entered, this, SceneStringNames::get_singleton()->_body_enter_tree); - node->disconnect(SceneStringNames::get_singleton()->tree_exited, this, SceneStringNames::get_singleton()->_body_exit_tree); + node->disconnect(SceneStringNames::get_singleton()->tree_exiting, this, SceneStringNames::get_singleton()->_body_exit_tree); } } @@ -276,7 +276,7 @@ void Area::_clear_monitoring() { emit_signal(SceneStringNames::get_singleton()->area_exited, obj); node->disconnect(SceneStringNames::get_singleton()->tree_entered, this, SceneStringNames::get_singleton()->_area_enter_tree); - node->disconnect(SceneStringNames::get_singleton()->tree_exited, this, SceneStringNames::get_singleton()->_area_exit_tree); + node->disconnect(SceneStringNames::get_singleton()->tree_exiting, this, SceneStringNames::get_singleton()->_area_exit_tree); } } } @@ -366,7 +366,7 @@ void Area::_area_inout(int p_status, const RID &p_area, int p_instance, int p_ar E->get().in_tree = node && node->is_inside_tree(); if (node) { node->connect(SceneStringNames::get_singleton()->tree_entered, this, SceneStringNames::get_singleton()->_area_enter_tree, make_binds(objid)); - node->connect(SceneStringNames::get_singleton()->tree_exited, this, SceneStringNames::get_singleton()->_area_exit_tree, make_binds(objid)); + node->connect(SceneStringNames::get_singleton()->tree_exiting, this, SceneStringNames::get_singleton()->_area_exit_tree, make_binds(objid)); if (E->get().in_tree) { emit_signal(SceneStringNames::get_singleton()->area_entered, node); } @@ -393,7 +393,7 @@ void Area::_area_inout(int p_status, const RID &p_area, int p_instance, int p_ar if (node) { node->disconnect(SceneStringNames::get_singleton()->tree_entered, this, SceneStringNames::get_singleton()->_area_enter_tree); - node->disconnect(SceneStringNames::get_singleton()->tree_exited, this, SceneStringNames::get_singleton()->_area_exit_tree); + node->disconnect(SceneStringNames::get_singleton()->tree_exiting, this, SceneStringNames::get_singleton()->_area_exit_tree); if (E->get().in_tree) { emit_signal(SceneStringNames::get_singleton()->area_exited, obj); } diff --git a/scene/3d/physics_body.cpp b/scene/3d/physics_body.cpp index 7d638d8737f..a15a7dceadf 100644 --- a/scene/3d/physics_body.cpp +++ b/scene/3d/physics_body.cpp @@ -318,7 +318,7 @@ void RigidBody::_body_inout(int p_status, ObjectID p_instance, int p_body_shape, E->get().in_tree = node && node->is_inside_tree(); if (node) { node->connect(SceneStringNames::get_singleton()->tree_entered, this, SceneStringNames::get_singleton()->_body_enter_tree, make_binds(objid)); - node->connect(SceneStringNames::get_singleton()->tree_exited, this, SceneStringNames::get_singleton()->_body_exit_tree, make_binds(objid)); + node->connect(SceneStringNames::get_singleton()->tree_exiting, this, SceneStringNames::get_singleton()->_body_exit_tree, make_binds(objid)); if (E->get().in_tree) { emit_signal(SceneStringNames::get_singleton()->body_entered, node); } @@ -345,7 +345,7 @@ void RigidBody::_body_inout(int p_status, ObjectID p_instance, int p_body_shape, if (node) { node->disconnect(SceneStringNames::get_singleton()->tree_entered, this, SceneStringNames::get_singleton()->_body_enter_tree); - node->disconnect(SceneStringNames::get_singleton()->tree_exited, this, SceneStringNames::get_singleton()->_body_exit_tree); + node->disconnect(SceneStringNames::get_singleton()->tree_exiting, this, SceneStringNames::get_singleton()->_body_exit_tree); if (in_tree) emit_signal(SceneStringNames::get_singleton()->body_exited, obj); } diff --git a/scene/3d/visibility_notifier.cpp b/scene/3d/visibility_notifier.cpp index a8818a06c33..9d6e4941f3d 100644 --- a/scene/3d/visibility_notifier.cpp +++ b/scene/3d/visibility_notifier.cpp @@ -170,7 +170,7 @@ void VisibilityEnabler::_find_nodes(Node *p_node) { if (add) { - p_node->connect(SceneStringNames::get_singleton()->tree_exited, this, "_node_removed", varray(p_node), CONNECT_ONESHOT); + p_node->connect(SceneStringNames::get_singleton()->tree_exiting, this, "_node_removed", varray(p_node), CONNECT_ONESHOT); nodes[p_node] = meta; _change_node_state(p_node, false); } @@ -208,7 +208,7 @@ void VisibilityEnabler::_notification(int p_what) { if (!visible) _change_node_state(E->key(), true); - E->key()->disconnect(SceneStringNames::get_singleton()->tree_exited, this, "_node_removed"); + E->key()->disconnect(SceneStringNames::get_singleton()->tree_exiting, this, "_node_removed"); } nodes.clear(); @@ -240,7 +240,7 @@ void VisibilityEnabler::_node_removed(Node *p_node) { if (!visible) _change_node_state(p_node, true); - p_node->disconnect(SceneStringNames::get_singleton()->tree_exited, this, "_node_removed"); + p_node->disconnect(SceneStringNames::get_singleton()->tree_exiting, this, "_node_removed"); nodes.erase(p_node); } diff --git a/scene/animation/animation_cache.cpp b/scene/animation/animation_cache.cpp index df83be6d504..949a0be3bcc 100644 --- a/scene/animation/animation_cache.cpp +++ b/scene/animation/animation_cache.cpp @@ -56,7 +56,7 @@ void AnimationCache::_clear_cache() { while (connected_nodes.size()) { - connected_nodes.front()->get()->disconnect("tree_exited", this, "_node_exit_tree"); + connected_nodes.front()->get()->disconnect("tree_exiting", this, "_node_exit_tree"); connected_nodes.erase(connected_nodes.front()); } path_cache.clear(); @@ -181,7 +181,7 @@ void AnimationCache::_update_cache() { if (!connected_nodes.has(path.node)) { connected_nodes.insert(path.node); - path.node->connect("tree_exited", this, "_node_exit_tree", Node::make_binds(path.node), CONNECT_ONESHOT); + path.node->connect("tree_exiting", this, "_node_exit_tree", Node::make_binds(path.node), CONNECT_ONESHOT); } } diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index 2a276981dbc..0a051cdb9b6 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -261,8 +261,8 @@ void AnimationPlayer::_ensure_node_caches(AnimationData *p_anim) { } { - if (!child->is_connected("tree_exited", this, "_node_removed")) - child->connect("tree_exited", this, "_node_removed", make_binds(child), CONNECT_ONESHOT); + if (!child->is_connected("tree_exiting", this, "_node_removed")) + child->connect("tree_exiting", this, "_node_removed", make_binds(child), CONNECT_ONESHOT); } TrackNodeCacheKey key; diff --git a/scene/gui/scroll_bar.cpp b/scene/gui/scroll_bar.cpp index d54500bc513..95fcda2db33 100644 --- a/scene/gui/scroll_bar.cpp +++ b/scene/gui/scroll_bar.cpp @@ -323,14 +323,14 @@ void ScrollBar::_notification(int p_what) { if (drag_slave) { drag_slave->connect("gui_input", this, "_drag_slave_input"); - drag_slave->connect("tree_exited", this, "_drag_slave_exit", varray(), CONNECT_ONESHOT); + drag_slave->connect("tree_exiting", this, "_drag_slave_exit", varray(), CONNECT_ONESHOT); } } if (p_what == NOTIFICATION_EXIT_TREE) { if (drag_slave) { drag_slave->disconnect("gui_input", this, "_drag_slave_input"); - drag_slave->disconnect("tree_exited", this, "_drag_slave_exit"); + drag_slave->disconnect("tree_exiting", this, "_drag_slave_exit"); } drag_slave = NULL; @@ -655,7 +655,7 @@ void ScrollBar::set_drag_slave(const NodePath &p_path) { if (drag_slave) { drag_slave->disconnect("gui_input", this, "_drag_slave_input"); - drag_slave->disconnect("tree_exited", this, "_drag_slave_exit"); + drag_slave->disconnect("tree_exiting", this, "_drag_slave_exit"); } } @@ -671,7 +671,7 @@ void ScrollBar::set_drag_slave(const NodePath &p_path) { if (drag_slave) { drag_slave->connect("gui_input", this, "_drag_slave_input"); - drag_slave->connect("tree_exited", this, "_drag_slave_exit", varray(), CONNECT_ONESHOT); + drag_slave->connect("tree_exiting", this, "_drag_slave_exit", varray(), CONNECT_ONESHOT); } } } diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 5f39c6285f0..148cdaf526e 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -275,7 +275,7 @@ void Node::_propagate_exit_tree() { get_script_instance()->call_multilevel(SceneStringNames::get_singleton()->_exit_tree, NULL, 0); } - emit_signal(SceneStringNames::get_singleton()->tree_exited); + emit_signal(SceneStringNames::get_singleton()->tree_exiting); notification(NOTIFICATION_EXIT_TREE, true); if (data.tree) @@ -297,6 +297,8 @@ void Node::_propagate_exit_tree() { data.ready_notified = false; data.tree = NULL; data.depth = -1; + + emit_signal(SceneStringNames::get_singleton()->tree_exited); } void Node::move_child(Node *p_child, int p_pos) { @@ -2952,6 +2954,7 @@ void Node::_bind_methods() { ADD_SIGNAL(MethodInfo("renamed")); ADD_SIGNAL(MethodInfo("tree_entered")); + ADD_SIGNAL(MethodInfo("tree_exiting")); ADD_SIGNAL(MethodInfo("tree_exited")); //ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "process/process" ),"set_process","is_processing") ; diff --git a/scene/scene_string_names.cpp b/scene/scene_string_names.cpp index 7d8dfea2bcc..fdce0eb2b6d 100644 --- a/scene/scene_string_names.cpp +++ b/scene/scene_string_names.cpp @@ -49,6 +49,7 @@ SceneStringNames::SceneStringNames() { shader_unshaded = StaticCString::create("shader/unshaded"); shading_mode = StaticCString::create("shader/shading_mode"); tree_entered = StaticCString::create("tree_entered"); + tree_exiting = StaticCString::create("tree_exiting"); tree_exited = StaticCString::create("tree_exited"); item_rect_changed = StaticCString::create("item_rect_changed"); size_flags_changed = StaticCString::create("size_flags_changed"); diff --git a/scene/scene_string_names.h b/scene/scene_string_names.h index 1b30d7c1bf2..63a9a5db4dc 100644 --- a/scene/scene_string_names.h +++ b/scene/scene_string_names.h @@ -69,6 +69,7 @@ public: StringName shader_unshaded; StringName shading_mode; StringName tree_entered; + StringName tree_exiting; StringName tree_exited; StringName size_flags_changed; StringName minimum_size_changed;