Skip to content

Commit

Permalink
Fixes godotengine/godot-proposals#8850: Synchronously notify the scen…
Browse files Browse the repository at this point in the history
…e tree of changes
  • Loading branch information
janosdebugs committed Apr 15, 2024
1 parent b8fa48b commit 6210800
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions doc/classes/SceneTree.xml
Expand Up @@ -278,6 +278,12 @@
</member>
</members>
<signals>
<signal name="node_adding">
<param index="0" name="node" type="Node" />
<description>
Emitted before the [param node] enters this tree.
</description>
</signal>
<signal name="node_added">
<param index="0" name="node" type="Node" />
<description>
Expand Down
2 changes: 2 additions & 0 deletions scene/main/node.cpp
Expand Up @@ -291,6 +291,8 @@ void Node::_propagate_enter_tree() {
E.value.group = data.tree->add_to_group(E.key, this);
}

data.tree->node_adding(this);

notification(NOTIFICATION_ENTER_TREE);

GDVIRTUAL_CALL(_enter_tree);
Expand Down
5 changes: 5 additions & 0 deletions scene/main/scene_tree.cpp
Expand Up @@ -123,6 +123,10 @@ void SceneTree::tree_changed() {
emit_signal(tree_changed_name);
}

void SceneTree::node_adding(Node *p_node) {
emit_signal(node_adding_name, p_node);
}

void SceneTree::node_added(Node *p_node) {
emit_signal(node_added_name, p_node);
}
Expand Down Expand Up @@ -1679,6 +1683,7 @@ void SceneTree::_bind_methods() {

ADD_SIGNAL(MethodInfo("tree_changed"));
ADD_SIGNAL(MethodInfo("tree_process_mode_changed")); //editor only signal, but due to API hash it can't be removed in run-time
ADD_SIGNAL(MethodInfo("node_adding", PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, "Node")));
ADD_SIGNAL(MethodInfo("node_added", PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, "Node")));
ADD_SIGNAL(MethodInfo("node_removed", PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, "Node")));
ADD_SIGNAL(MethodInfo("node_renamed", PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, "Node")));
Expand Down
2 changes: 2 additions & 0 deletions scene/main/scene_tree.h
Expand Up @@ -140,6 +140,7 @@ class SceneTree : public MainLoop {
bool _physics_interpolation_enabled = false;

StringName tree_changed_name = "tree_changed";
StringName node_adding_name = "node_adding";
StringName node_added_name = "node_added";
StringName node_removed_name = "node_removed";
StringName node_renamed_name = "node_renamed";
Expand Down Expand Up @@ -204,6 +205,7 @@ class SceneTree : public MainLoop {
friend class Node;

void tree_changed();
void node_adding(Node *p_node);
void node_added(Node *p_node);
void node_removed(Node *p_node);
void node_renamed(Node *p_node);
Expand Down

0 comments on commit 6210800

Please sign in to comment.