How to add node action "Remove Pin" from a custom K2Node like the Select node

Hi, I’m make a custom k2 node and following K2Node_Select to enable my custom node to add and remove pins.

But, the IK2Node_AddPinInterface interface only allows adding new pins but not removing pins. As I dive into the source code, I found that the node action “Remove Pin” originated from BlueprintEditor.cpp , the function CreateGraphEditorWidget.

How can I enable my k2node to remove pins?

you could probably just call ReconstructNode after changing the pins?

Well, the point is I cannot find the entry action where I can remove pins, by either right clicking one pin or clicking the node itself.

you can create a custom function with CallInEditor that will show up in the details panel.

I did it like this:

void UOGNode_ComboGate::GetNodeContextMenuActions(UToolMenu* Menu, UGraphNodeContextMenuContext* Context) const
{
Super::GetNodeContextMenuActions(Menu, Context);
	
////////////////////////

// Remove selected pin

FToolMenuSection& SectionPin = Menu->FindOrAddSection(FName("EdGraphSchemaPinActions"));

SectionPin.AddDynamicEntry("RemovePinDynamicEntry", FNewToolMenuSectionDelegate::CreateLambda([Context](FToolMenuSection& InSection)
		{
				FToolUIActionChoice RemovePin_Action(FExecuteAction::CreateLambda([Context]()
					{
						//UE_LOG(LogTemp, Warning, TEXT("CLICK REMOVE"));
						Cast<UOGNode_ComboGate>(Context->Node)->RemoveExecPin(FName(Context->Pin->GetName()));
					}));

				if (Context->Pin && Context->Pin->Direction == EGPD_Input && Context->Node->Pins.Num() > 3)
				{
					InSection.AddEntry(FToolMenuEntry::InitMenuEntry(FName("RemovePin"), FText::FromString("Remove Pin"), FText::FromString(TEXT("Remove Pin")), FSlateIcon(FName("OGStyle"), FName("Icons.Remove")), RemovePin_Action));
				}
		}));


	///////////////////////////////////

3 Likes