@@ -67,6 +67,10 @@ void SFlowGraphEditor::BindGraphCommands()
6767
6868 CommandList->MapAction (GraphEditorCommands.StraightenConnections ,
6969 FExecuteAction::CreateSP (this , &SFlowGraphEditor::OnStraightenConnections));
70+
71+ CommandList->MapAction (GraphEditorCommands.DeleteAndReconnectNodes ,
72+ FExecuteAction::CreateSP (this , &SFlowGraphEditor::DeleteSelectedNodes),
73+ FCanExecuteAction::CreateSP (this , &SFlowGraphEditor::CanDeleteNodes));
7074
7175 // Generic Node commands
7276 CommandList->MapAction (GenericCommands.Undo ,
@@ -374,6 +378,76 @@ TSet<UFlowGraphNode*> SFlowGraphEditor::GetSelectedFlowNodes() const
374378 return Result;
375379}
376380
381+ void SFlowGraphEditor::ReconnectExecPins (const UFlowGraphNode* Node)
382+ {
383+ if (Node == nullptr )
384+ {
385+ return ;
386+ }
387+
388+ UEdGraphPin* InputPin = nullptr ;
389+ UEdGraphPin* OutputPin = nullptr ;
390+
391+ for (UEdGraphPin* Pin : Node->InputPins )
392+ {
393+ if (Pin->HasAnyConnections ())
394+ {
395+ if (InputPin)
396+ {
397+ // more that one connected input pins - do not reconnect anything
398+ return ;
399+ }
400+
401+ if (Pin)
402+ {
403+ InputPin = Pin;
404+ }
405+ }
406+ else if (InputPin == nullptr )
407+ {
408+ // first pin doesn't have any connections - do not reconnect anything, because we probably don't know expected result for user
409+ return ;
410+ }
411+ }
412+
413+ for (UEdGraphPin* Pin : Node->OutputPins )
414+ {
415+ if (Pin->HasAnyConnections ())
416+ {
417+ if (OutputPin)
418+ {
419+ // more that one connected output pins - do not reconnect anything
420+ return ;
421+ }
422+
423+ if (Pin)
424+ {
425+ OutputPin = Pin;
426+ }
427+ }
428+ else if (OutputPin == nullptr )
429+ {
430+ // first pin doesn't have any connections - do not reconnect anything, because we probably don't know expected result for user
431+ return ;
432+ }
433+ }
434+
435+ if (InputPin && OutputPin)
436+ {
437+ // Make a connection from every incoming exec pin to every outgoing then pin
438+ for (UEdGraphPin* const IncomingConnectionPin : InputPin->LinkedTo )
439+ {
440+ if (IncomingConnectionPin)
441+ {
442+ for (UEdGraphPin* const ConnectedCompletePin : OutputPin->LinkedTo )
443+ {
444+ IncomingConnectionPin->MakeLinkTo (ConnectedCompletePin);
445+ }
446+ }
447+ }
448+ }
449+ }
450+
377451void SFlowGraphEditor::DeleteSelectedNodes ()
378452{
379453 const FScopedTransaction Transaction (LOCTEXT (" DeleteSelectedNode" , " Delete Selected Node" ));
@@ -394,6 +468,12 @@ void SFlowGraphEditor::DeleteSelectedNodes()
394468 {
395469 const FGuid NodeGuid = FlowGraphNode->GetFlowNode ()->GetGuid ();
396470
471+ // If the user is pressing shift then try and reconnect the pins
472+ if (FSlateApplication::Get ().GetModifierKeys ().IsShiftDown ())
473+ {
474+ ReconnectExecPins (FlowGraphNode);
475+ }
476+
397477 GetCurrentGraph ()->GetSchema ()->BreakNodeLinks (*Node);
398478 Node->DestroyNode ();
399479
0 commit comments