Could not execution pins on my cust omK2Node

I create an “empty” (do nothing) k2node, that only has an exec input and output.

When i connect the input exec pin i got the error when i press compile:
Unexpected node type K2Node_MyNode encountered at YYY My Node

K2Node_myNode.h

#pragma once

#include "CoreMinimal.h"
#include "K2Node.h"

#include "K2Node_MyNode.generated.h"

UCLASS()
class MY_API UK2Node_MyNode : public UK2Node {
  GENERATED_BODY()

public:
  virtual void AllocateDefaultPins() override;
  virtual FText GetNodeTitle(ENodeTitleType::Type TitleType) const override;
  virtual bool IsNodePure() const override;
  virtual void GetMenuActions(FBlueprintActionDatabaseRegistrar& ActionRegistrar) const override;
};

K2Node_MyNode.cpp

#include "K2Node_MyNode.h"

#include "BlueprintActionDatabaseRegistrar.h"
#include "BlueprintNodeSpawner.h"

void UK2Node_MyNode::AllocateDefaultPins() {
  Super::AllocateDefaultPins();
  CreatePin(EGPD_Input, UEdGraphSchema_K2::PC_Exec, UEdGraphSchema_K2::PN_Execute);
  CreatePin(EGPD_Output, UEdGraphSchema_K2::PC_Exec, UEdGraphSchema_K2::PN_Then);
}

bool UK2Node_MyNode::IsNodePure() const {
  return false;
}

FText UK2Node_MyNode::GetNodeTitle(ENodeTitleType::Type TitleType) const {
  return FText::FromString(TEXT("YYY My Node"));
}

void UK2Node_MyNode::GetMenuActions(FBlueprintActionDatabaseRegistrar& ActionRegistrar) const {
  const UClass* Action = GetClass();
  if (ActionRegistrar.IsOpenForRegistration(Action)) {
    UBlueprintNodeSpawner* NodeSpawner = UBlueprintNodeSpawner::Create(GetClass());
    check(NodeSpawner != nullptr);
    ActionRegistrar.AddBlueprintAction(Action, NodeSpawner);
  }
}

What I am doing wrong? :downcast_face_with_sweat:

You’re missing at least two things:

  1. You need to override IsNodeSafeToIgnore to return true.
  2. You need to override ExpandNode to (at a minimum) call BreakAllNodeLinks

Take a look at this tutorial I wrote a few years ago that covers a lot of details like this for writing K2nodes. It also goes into details as to why you need those things.

This page also has some good additional details, but you should start with mine first.

Thanks for your tutorials, i read them yesterday. :+1:

I found the problem :rofl: restart Unreal after added ExpandNode (Refresh Node was not enough)