diff --git a/editor/docks/scene_tree_dock.cpp b/editor/docks/scene_tree_dock.cpp index 6e3a174ef7..3f3d987f8d 100644 --- a/editor/docks/scene_tree_dock.cpp +++ b/editor/docks/scene_tree_dock.cpp @@ -2925,12 +2925,9 @@ void SceneTreeDock::_selection_changed() { } // Untrack script changes in previously selected nodes. - for (Node *node : node_previous_selection) { - node->disconnect(CoreStringName(script_changed), callable_mp(this, &SceneTreeDock::_queue_update_script_button)); - } + clear_previous_node_selection(); // Track script changes in newly selected nodes. - node_previous_selection.clear(); node_previous_selection.reserve(editor_selection->get_selection().size()); for (const KeyValue &E : editor_selection->get_selection()) { Node *node = E.key; @@ -3373,6 +3370,13 @@ static bool _is_same_selection(const Vector &p_first, const List return true; } +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)); + } + node_previous_selection.clear(); +} + void SceneTreeDock::set_selection(const Vector &p_nodes) { // If the nodes selected are the same independently of order then return early. if (_is_same_selection(p_nodes, editor_selection->get_full_selected_node_list())) { diff --git a/editor/docks/scene_tree_dock.h b/editor/docks/scene_tree_dock.h index aa1002420c..943cef1fd5 100644 --- a/editor/docks/scene_tree_dock.h +++ b/editor/docks/scene_tree_dock.h @@ -324,6 +324,7 @@ public: void set_edited_scene(Node *p_scene); void instantiate(const String &p_file); void instantiate_scenes(const Vector &p_files, Node *p_parent = nullptr); + void clear_previous_node_selection(); void set_selection(const Vector &p_nodes); void set_selected(Node *p_node, bool p_emit_selected = false); void fill_path_renames(Node *p_node, Node *p_new_parent, HashMap *p_renames); diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 8b170b0389..ae422c98cf 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -4248,6 +4248,7 @@ void EditorNode::_set_current_scene_nocheck(int p_idx) { Node *old_scene = get_editor_data().get_edited_scene_root(); editor_selection->clear(); + SceneTreeDock::get_singleton()->clear_previous_node_selection(); editor_data.set_edited_scene(p_idx); Node *new_scene = editor_data.get_edited_scene_root();