@@ -127,6 +127,15 @@ void AnimationNodeBlendTreeEditor::update_graph() {
127127
128128 visible_properties.clear ();
129129
130+ // Store selected nodes before clearing the graph.
131+ List<StringName> selected_nodes;
132+ for (int i = 0 ; i < graph->get_child_count (); i++) {
133+ GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child (i));
134+ if (gn && gn->is_selected ()) {
135+ selected_nodes.push_back (gn->get_name ());
136+ }
137+ }
138+
130139 graph->set_scroll_offset (blend_tree->get_graph_offset () * EDSCALE);
131140
132141 graph->clear_connections ();
@@ -304,6 +313,17 @@ void AnimationNodeBlendTreeEditor::update_graph() {
304313 graph->set_minimap_opacity (graph_minimap_opacity);
305314 float graph_lines_curvature = EDITOR_GET (" editors/visual_editors/lines_curvature" );
306315 graph->set_connection_lines_curvature (graph_lines_curvature);
316+
317+ // Restore selected nodes after graph reconstruction.
318+ for (const StringName &name : selected_nodes) {
319+ for (int i = 0 ; i < graph->get_child_count (); i++) {
320+ GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child (i));
321+ if (gn && gn->get_name () == name) {
322+ gn->set_selected (true );
323+ break ;
324+ }
325+ }
326+ }
307327}
308328
309329void AnimationNodeBlendTreeEditor::_file_opened (const String &p_file) {
@@ -539,6 +559,9 @@ void AnimationNodeBlendTreeEditor::_delete_node_request(const String &p_which) {
539559 undo_redo->add_do_method (this , " update_graph" );
540560 undo_redo->add_undo_method (this , " update_graph" );
541561 undo_redo->commit_action ();
562+
563+ // Return selection to host BlendTree node.
564+ EditorNode::get_singleton ()->push_item (blend_tree.ptr (), " " , true );
542565}
543566
544567void AnimationNodeBlendTreeEditor::_delete_nodes_request (const TypedArray<StringName> &p_nodes) {
@@ -597,6 +620,22 @@ void AnimationNodeBlendTreeEditor::_node_selected(Object *p_node) {
597620 EditorNode::get_singleton ()->push_item (anode.ptr (), " " , true );
598621}
599622
623+ void AnimationNodeBlendTreeEditor::_node_deselected (Object *p_node) {
624+ // Check if no nodes are selected, return selection to host BlendTree node.
625+ bool any_selected = false ;
626+ for (int i = 0 ; i < graph->get_child_count (); i++) {
627+ GraphNode *gn = Object::cast_to<GraphNode>(graph->get_child (i));
628+ if (gn && gn->is_selected ()) {
629+ any_selected = true ;
630+ break ;
631+ }
632+ }
633+
634+ if (!any_selected) {
635+ EditorNode::get_singleton ()->push_item (blend_tree.ptr (), " " , true );
636+ }
637+ }
638+
600639void AnimationNodeBlendTreeEditor::_open_in_editor (const String &p_which) {
601640 Ref<AnimationNode> an = blend_tree->get_node (p_which);
602641 ERR_FAIL_COND (an.is_null ());
@@ -1192,6 +1231,7 @@ AnimationNodeBlendTreeEditor::AnimationNodeBlendTreeEditor() {
11921231 graph->connect (" connection_request" , callable_mp (this , &AnimationNodeBlendTreeEditor::_connection_request), CONNECT_DEFERRED);
11931232 graph->connect (" disconnection_request" , callable_mp (this , &AnimationNodeBlendTreeEditor::_disconnection_request), CONNECT_DEFERRED);
11941233 graph->connect (" node_selected" , callable_mp (this , &AnimationNodeBlendTreeEditor::_node_selected));
1234+ graph->connect (" node_deselected" , callable_mp (this , &AnimationNodeBlendTreeEditor::_node_deselected));
11951235 graph->connect (" scroll_offset_changed" , callable_mp (this , &AnimationNodeBlendTreeEditor::_scroll_changed));
11961236 graph->connect (" delete_nodes_request" , callable_mp (this , &AnimationNodeBlendTreeEditor::_delete_nodes_request));
11971237 graph->connect (" popup_request" , callable_mp (this , &AnimationNodeBlendTreeEditor::_popup_request));
0 commit comments