1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-11 13:10:58 +00:00

Add a signal to notify when children nodes enter or exit tree

-Allows more fine grained notifications (hence better performance) than using the global scene tree signals (node added and removed).
-Required for #55950

(cherry picked from commit fbd9599b04)
This commit is contained in:
reduz
2022-02-02 11:22:11 +01:00
committed by Rémi Verschelde
parent ca432727d9
commit e4e3f7d157
4 changed files with 30 additions and 0 deletions

View File

@@ -212,6 +212,12 @@ void Node::_propagate_enter_tree() {
data.tree->node_added(this);
if (data.parent) {
Variant c = this;
const Variant *cptr = &c;
data.parent->emit_signal(SceneStringNames::get_singleton()->child_entered_tree, &cptr, 1);
}
data.blocked++;
//block while adding children
@@ -305,6 +311,12 @@ void Node::_propagate_exit_tree() {
data.tree->node_removed(this);
}
if (data.parent) {
Variant c = this;
const Variant *cptr = &c;
data.parent->emit_signal(SceneStringNames::get_singleton()->child_exited_tree, &cptr, 1);
}
// exit groups
for (Map<StringName, GroupData>::Element *E = data.grouped.front(); E; E = E->next()) {
@@ -2925,6 +2937,8 @@ void Node::_bind_methods() {
ADD_SIGNAL(MethodInfo("tree_entered"));
ADD_SIGNAL(MethodInfo("tree_exiting"));
ADD_SIGNAL(MethodInfo("tree_exited"));
ADD_SIGNAL(MethodInfo("child_entered_tree", PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT, "Node")));
ADD_SIGNAL(MethodInfo("child_exited_tree", PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT, "Node")));
ADD_PROPERTY(PropertyInfo(Variant::INT, "pause_mode", PROPERTY_HINT_ENUM, "Inherit,Stop,Process"), "set_pause_mode", "get_pause_mode");