K2Node notes
K2Node
Bare Minimum
UCLASS()
class UK2Node_MyNode : public UK2Node
{
GENERATED_BODY()
public:
virtual void AllocateDefaultPins() override;
virtual FText GetNodeTitle(ENodeTitleType::Type TitleType) const override;
virtual FText GetMenuCategory() const override;
virtual void GetMenuActions(FBlueprintActionDatabaseRegistrar& ActionRegistrar) const override;
};
Creating pins
Default input exec pin:
CreatePin(EGPD_Input, UEdGraphSchema_K2::PC_Exec, UEdGraphSchema_K2::PN_Execute);
Default output exec pin:
CreatePin(EGPD_Output, UEdGraphSchema_K2::PC_Exec, UEdGraphSchema_K2::PN_Then);
UObject input pin with specific subclass:
CreatePin(EGPD_Input, UEdGraphSchema_K2::PC_Object, UMyObject::StaticClass(), "MyObject");
Menu action
void UK2Node_MyNode::GetMenuActions(FBlueprintActionDatabaseRegistrar& ActionRegistrar) const
{
UClass* ActionKey = GetClass();
if (ActionRegistrar.IsOpenForRegistration(ActionKey))
{
UBlueprintNodeSpawner* Spawner = UBlueprintNodeSpawner::Create(GetClass());
check(Spawner);
ActionRegistrar.AddBlueprintAction(ActionKey, Spawner);
}
}
Disallow wiring the input pin
bool UK2Node_MyNode::IsConnectionDisallowed(
const UEdGraphPin* MyPin,
const UEdGraphPin* OtherPin,
FString& OutReason) const
{
if (MyPin->PinName == FName("MyPinName"))
{
OutReason = TEXT("Cannot wire this pin, must be set directly");
return true;
}
return Super::IsConnectionDisallowed(MyPin, OtherPin, OutReason);
}
Reacting to value change
Implement the following function if you need to react to a value change on a specific pin:
UK2Node::PinDefaultValueChanged(UEdGraphPin* Pin);