Fix "Some nodes are referenced by animation tracks" when deleting instance

This commit is contained in:
Haoyu Qiu 2023-09-28 22:35:35 +08:00
parent 4c3dc26367
commit b50d0ebb28

View file

@ -1546,6 +1546,14 @@ void SceneTreeDock::_fill_path_renames(Vector<StringName> base_path, Vector<Stri
}
bool SceneTreeDock::_has_tracks_to_delete(Node *p_node, List<Node *> &p_to_delete) const {
// Skip if this node will be deleted.
for (const Node *F : p_to_delete) {
if (F == p_node || F->is_ancestor_of(p_node)) {
return false;
}
}
// This is an AnimationPlayer that survives the deletion.
AnimationPlayer *ap = Object::cast_to<AnimationPlayer>(p_node);
if (ap) {
Node *root = ap->get_node(ap->get_root());
@ -1574,11 +1582,13 @@ bool SceneTreeDock::_has_tracks_to_delete(Node *p_node, List<Node *> &p_to_delet
}
}
// Recursively check child nodes.
for (int i = 0; i < p_node->get_child_count(); i++) {
if (_has_tracks_to_delete(p_node->get_child(i), p_to_delete)) {
return true;
}
}
return false;
}