Skip to content

Commit

Permalink
Defer add_child propagation to next frame
Browse files Browse the repository at this point in the history
  • Loading branch information
rsubtil committed Dec 11, 2023
1 parent e89f8d1 commit 8c58590
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 6 additions & 2 deletions scene/main/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1421,8 +1421,12 @@ void Node::_add_child_nocheck(Node *p_child, const StringName &p_name, InternalM
//recognize children created in this node constructor
p_child->data.parent_owned = data.in_constructor;
add_child_notify(p_child);
notification(NOTIFICATION_CHILD_ORDER_CHANGED);
emit_signal(SNAME("child_order_changed"));
if(!deferred_add_child) {
deferred_add_child = true;
call_deferred("notification", NOTIFICATION_CHILD_ORDER_CHANGED);
call_deferred("emit_signal", SNAME("child_order_changed"));
set_deferred("deferred_add_child", false);
}
}

void Node::add_child(Node *p_child, bool p_force_readable_name, InternalMode p_internal) {
Expand Down
2 changes: 2 additions & 0 deletions scene/main/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,8 @@ class Node : public Object {

InternalMode get_internal_mode() const;

bool deferred_add_child = false;

void add_child(Node *p_child, bool p_force_readable_name = false, InternalMode p_internal = INTERNAL_MODE_DISABLED);
void add_sibling(Node *p_sibling, bool p_force_readable_name = false);
void remove_child(Node *p_child);
Expand Down

0 comments on commit 8c58590

Please sign in to comment.