Unexpected node Type error when compiling K2Node made only by "Then" & "Execute" pins

Hello Unreal Engine Community,

I’m currently facing an issue with a custom K2Node in Unreal Engine and seeking some assistance. I’ve created a custom node, UK2_FlexibleStruct, but when I try to compile, I receive the following error:
image

.h file


// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"

//クラスをここでImport
#include "K2Node.h"
#include "KismetCompiler.h"
#include "K2Node_CallFunction.h"
#include "BlueprintActionDatabaseRegistrar.h"
#include "BlueprintNodeSpawner.h"
#include "EditorCategoryUtils.h"
#include "EdGraph/EdGraphNode.h"
//
#include "K2_FlexibleStruct.generated.h"

/**
 *
 */
UCLASS(meta = (Keywords = "K2_FlexibleStruct"))
class UK2_FlexibleStruct : public UK2Node
{
	GENERATED_BODY()

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


};

.cpp file



#include "K2_FlexibleStruct.h"




namespace
{
	static const FName CustomExecuteName(TEXT("A"));
}

/// <summary> Visual SettingsNode
FLinearColor UK2_FlexibleStruct::GetNodeTitleColor() const
{
	float r = 242.0f/255.0f;
	float g = 189.0f/255.0f;
	float b = 27.0f/255.0f;
	return FLinearColor(r, g, b,1.0f);
}

FText UK2_FlexibleStruct::GetNodeTitle(ENodeTitleType::Type TitleType) const
{
	// 名前空間とキーを指定してローカライズ可能なテキストを生成する
	return FText::FromString("FlexibleStruct");
}
FText UK2_FlexibleStruct::GetMenuCategory() const
{
	// カテゴリ「Math」に登録する
	return FEditorCategoryUtils::GetCommonCategory(FCommonEditorCategory::FlowControl);
}

/// </summary>
void UK2_FlexibleStruct::AllocateDefaultPins() { //..デフォルトのピンのコンテナの役割
	const UEdGraphSchema_K2* K2Schema = GetDefault<UEdGraphSchema_K2>();
	bCanRenameNode = 0;
	CreatePin(EGPD_Input, TEXT("exec"), TEXT("execute"));
	CreatePin(EGPD_Output, TEXT("then"), TEXT("thens"));
	Super::AllocateDefaultPins();
}
bool UK2_FlexibleStruct::IsNodePure() const
{
	return false;
}

void UK2_FlexibleStruct::GetMenuActions(FBlueprintActionDatabaseRegistrar& ActionRegistrar) const
{//..メニューをBPGraphから検索して表示されるようにする
	UClass* ActionKey = GetClass();
	if (ActionRegistrar.IsOpenForRegistration(ActionKey))
	{
		UBlueprintNodeSpawner* NodeSpawner = UBlueprintNodeSpawner::Create(GetClass());
		check(NodeSpawner != nullptr);

		ActionRegistrar.AddBlueprintAction(ActionKey, NodeSpawner);
	}
}

Sorry there are some other language there, its some of my comment.

Only thing I did here was trying to make smallest node, that there has to be then and exec pin.

But It’s not working. Is there something I did wrong ? Or maybe I need some specific function for this situation or I need to add other pin to make my node work well?

I appreciate any help or guidance someone can provide. Thank you!

Edit:
I’m using UE5.2.1 and I implemented this node as runtime blank plugin inside my project.

A number of things:

  1. You should probably be overriding IsNodeSafeToIgnore to return true. The alternative (when nodes aren’t ignored) is a much more complicated implementation.
  2. You should also be overriding ExpandNode to call BreakAllNodeLinks. Ultimately this function will be what replaces your node with the other nodes that aren’t ignored.
  3. The second parameter to CreatePin shouldn’t be created manually. You should be using the constants from the UEdGraphSchema_K2 scope.
  4. There is no PinCategory of type “then”. The output pin should also use the UEdGraphSchema_K2::PC_Exec category just as the input pin does.
  5. While you can specify the name of the pin as the third parameter (and most of the time you have to), you should use the ones provided by the schema (UEdGraphSchema_K2::PN_Execute & UEdGraphSchema_K2::PN_Then) for the primary execution pins (if/when your node requires them). There’s built in logic to the blueprint graph that is designed to work with those specific names and if you don’t use them, your node won’t always work in the graph the same as similar nodes.
  6. Unless you have a very specific reason, calling Super:: should come first and not last (as you do in AllocateDefaultPins). The exceptions here are where the function is part of a shutdown process like EndPlay in which case the Super:: call should come last, but this is really relevant to K2Nodes.

Thank you so much for the reply. Sorry if it isn’t but your response looks similar to GPT for me.
I will respond feedback after the solution.

It’s not the first time I’ve been told I failed the Turing Test. :smiley:

But no, I’ve never used GPT for anything. I’ve just been programming for 20+ years, unreal for 10 and UE4/5 and custom k2nodes for 5.

CustomNode.zip (21.7 MB)

Project with working implementation through a plugin.

Perhaps you skipped adding the needed modules into the plugin?


		PrivateDependencyModuleNames.AddRange(
			new string[]
			{
				"CoreUObject",
				"Engine",
				"Slate",
				"SlateCore",
                "BlueprintGraph",
				"UnrealEd"
				// ... add private dependencies that you statically link with here ...	
			}

Generate the vs code from the uproject.

Oh my, I’m so sorry about that. Me being paranoid sometimes, make difficulty when communicating with other people.

There problem was a blueprint compile error, not a C++ one.

You should get the same thing if you compile the blueprint you placed that FlexibleStruct node into because it doesn’t look like you solved any of the problems that exist with their implementation.

Ok Thought the OP meant a plugin compile error.

Thank you very much ,for now the compiler error it self was gone.

The solution was the second one that needed to use BreakAllNodeLinks()but it seems that the logic don’t pass through.
Like connecting BeginFlexibleStructPrintString

Now I realize there are many functions and concepts about K2Nodes to learn and get some good result when coding.

That’s great! But eventually you’re going to need to address all of them to get your node working.

Good news! A few years ago I wrote a tutorial here that tries to condense a lot of the information in one place. Maybe it’ll help out if you hadn’t run across it before.

2 Likes

Thank you very much I will give it a try.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.