Skip to content

Commit

Permalink
Make replacing_by emit slightly earlier
Browse files Browse the repository at this point in the history
The `replacing_by` signal is mainly used to update the cached scene
root when replacing the scene root. Emit this signal a little early
to ensure that certain flags for the editor are not obsolete during
entering tree.
  • Loading branch information
Rindbee committed Jun 3, 2024
1 parent 5f1184e commit 382c230
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion doc/classes/Node.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1067,7 +1067,7 @@
<param index="0" name="node" type="Node" />
<description>
Emitted when this node is being replaced by the [param node], see [method replace_by].
This signal is emitted [i]after[/i] [param node] has been added as a child of the original parent node, but [i]before[/i] all original child nodes have been reparented to [param node].
This signal is emitted [i]before[/i] [param node] is added as a child of the original parent node.
</description>
</signal>
<signal name="tree_entered">
Expand Down
7 changes: 3 additions & 4 deletions scene/main/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3015,17 +3015,16 @@ void Node::replace_by(Node *p_node, bool p_keep_groups) {
_clean_up_owner();
}

Node *parent = data.parent;
int index_in_parent = get_index(false);
emit_signal(SNAME("replacing_by"), p_node);

Node *parent = data.parent;
if (data.parent) {
int index_in_parent = get_index(false);
parent->remove_child(this);
parent->add_child(p_node);
parent->move_child(p_node, index_in_parent);
}

emit_signal(SNAME("replacing_by"), p_node);

while (get_child_count()) {
Node *child = get_child(0);
remove_child(child);
Expand Down

0 comments on commit 382c230

Please sign in to comment.