Merge pull request #105337 from L2750558108/pr-fix-duplicate-in-node

Replace duplicate code of `is_ancestor_of()` in node.cpp
This commit is contained in:
Thaddeus Crews 2025-04-15 12:28:49 -05:00
commit c6341f49a1
No known key found for this signature in database
GPG key ID: 8C6E5FEB5FC03CCC

View file

@ -431,19 +431,7 @@ void Node::_propagate_enter_tree() {
void Node::_propagate_after_exit_tree() {
// Clear owner if it was not part of the pruned branch
if (data.owner) {
bool found = false;
Node *parent = data.parent;
while (parent) {
if (parent == data.owner) {
found = true;
break;
}
parent = parent->data.parent;
}
if (!found) {
if (!data.owner->is_ancestor_of(this)) {
_clean_up_owner();
}
}
@ -2364,17 +2352,7 @@ void Node::set_owner(Node *p_owner) {
return;
}
Node *check = get_parent();
bool owner_valid = false;
while (check) {
if (check == p_owner) {
owner_valid = true;
break;
}
check = check->data.parent;
}
bool owner_valid = p_owner->is_ancestor_of(this);
ERR_FAIL_COND_MSG(!owner_valid, "Invalid owner. Owner must be an ancestor in the tree.");