diff --git a/editor/docks/scene_tree_dock.cpp b/editor/docks/scene_tree_dock.cpp index 96de0a9006..0abeaac045 100644 --- a/editor/docks/scene_tree_dock.cpp +++ b/editor/docks/scene_tree_dock.cpp @@ -2936,7 +2936,7 @@ void SceneTreeDock::_selection_changed() { node_previous_selection.reserve(editor_selection->get_selection().size()); for (const KeyValue &E : editor_selection->get_selection()) { Node *node = E.key; - node_previous_selection.push_back(node); + node_previous_selection.push_back(node->get_instance_id()); node->connect(CoreStringName(script_changed), callable_mp(this, &SceneTreeDock::_queue_update_script_button)); } _queue_update_script_button(); @@ -3376,8 +3376,11 @@ static bool _is_same_selection(const Vector &p_first, const List } void SceneTreeDock::clear_previous_node_selection() { - for (Node *node : node_previous_selection) { - node->disconnect(CoreStringName(script_changed), callable_mp(this, &SceneTreeDock::_queue_update_script_button)); + for (const ObjectID &id : node_previous_selection) { + Node *node = ObjectDB::get_instance(id); + if (node) { + node->disconnect(CoreStringName(script_changed), callable_mp(this, &SceneTreeDock::_queue_update_script_button)); + } } node_previous_selection.clear(); } diff --git a/editor/docks/scene_tree_dock.h b/editor/docks/scene_tree_dock.h index 943cef1fd5..4425a895c9 100644 --- a/editor/docks/scene_tree_dock.h +++ b/editor/docks/scene_tree_dock.h @@ -135,7 +135,7 @@ class SceneTreeDock : public VBoxContainer { EditorData *editor_data = nullptr; EditorSelection *editor_selection = nullptr; - LocalVector node_previous_selection; + LocalVector node_previous_selection; bool update_script_button_queued = false; List node_clipboard;