From 27fb2181cda1dfc4a54b295dab7ccb96cf39cc9a Mon Sep 17 00:00:00 2001 From: kobewi Date: Wed, 20 Aug 2025 14:49:50 +0200 Subject: [PATCH] Track last selection using ObjectID --- editor/docks/scene_tree_dock.cpp | 9 ++++++--- editor/docks/scene_tree_dock.h | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/editor/docks/scene_tree_dock.cpp b/editor/docks/scene_tree_dock.cpp index 96de0a90063..0abeaac0451 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 943cef1fd52..4425a895c92 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;