How do I create my own blueprint node with C++?

Hey there, I have a basic question, how can I implement own blueprint nodes into the game. I added C++ code to my game which class type is “EdGraphNode”. So it creates an .h and an .cpp file of my class. So this is the .h file:

#pragma once

#include "EdGraph/EdGraphNode.h"
#include "MyEdGraphNode.generated.h"

/**
 * 
 */
UCLASS()
class EDIFY_API UMyEdGraphNode : public UEdGraphNode
{
	GENERATED_UCLASS_BODY()
	
};

My .cpp file:

#include "EDIFY.h"
#include "MyEdGraphNode.h"


UMyEdGraphNode::UMyEdGraphNode(const class FPostConstructInitializeProperties& PCIP)
	: Super(PCIP)
{
	//
}

I read that I have to implement this UFUNCTION in the files, but where? My tries to implement the line there where the // stands, that doesn’t work for me. Please help!

It’s pretty stright forward, you just make function like normally do in C++ and just mark it with UFUNCTION before it’s decleration in with specific specifiers and UHT and reflections system will do the rest. Arguments of function will be inputs of node, arguments with refrence type (for example FString&) will be turned in to output, return value will also be output, if function is not static it will have “Target” input which you plug object on which you call the function on. UHT will add spaces to function and argument names before uppercase letters.

So for example:

UCLASS()
class EDIFY_API UMyNodes : public UObject
{
        GENERATED_UCLASS_BODY()

        UFUNCTION(BlueprintCallable, Category="My Nodes")
        static int32 SomeIntReturningFunction(FString Text, int32 Number, FString& TextOut);

};

Will create node named “Some Int Returning Function” node in category “My Nodes” (btw you can create subcategories with | symbol) which will have input for text and integer and text output as well as integer return output. Static will remoce “Target” input considering you making class for your nodes i assume you dont need that, or else you making nodes ofr perticilar class, then you need to place in to that class. You can use BlueprintPure insted BlueprintCallable so it will create passive node without action input output, you can also create events. here docs about this

Lot of specifiers are not documented, you can explore wiki which has some examples, also i recommend you to explore engine source code to see how default nodes are declered, because they declered the same way, you can also find how they are declered in API refrence, here example Int + Int math which specially stylized math node and you already probably seen it in blueprints:

Look of nodes made specially for blueprints are coded in UGamepleyStatics and UKismetMathLibrary, but practicly most gameplay classes has atleast few functions declered as nodes, they are marked with blue file icon in API refrece

You can expose C++ varables blueprint too with UPROPERTY(BlueprintReadWrite)

1 Like

I guess what you want is to create a new UK2Node?

You only do that if you want to create custom kind of node, most things can be solved by functions

This is why I’m asking him, creating a new node is quite some work but gives you additional power on what you can do while being a very advanced topic.

Your function example doesn’t work for me. It says this: Error 2 error LNK2019: Reference to non-resolveded external symbol ""public: static int __cdecl UMyEdGraphNode::SomeIntReturningFunction(class FString,class FString &)" (?SomeIntReturningFunction@UMyEdGraphNode@@SAHVFString@@AEAV2@@Z)" in Funktion ""public: void __cdecl UMyEdGraphNode::execSomeIntReturningFunction(struct FFrame &,void * const)" (?execSomeIntReturningFunction@UMyEdGraphNode@@QEAAXAEAUFFrame@@QEAX@Z)". C:\Users\Johnny\Documents\Unreal Projects\EDIFY\Intermediate\ProjectFiles\MyEdGraphNode.cpp.obj EDIFY

Ok made it at my one… Forget to do this
void UTestEdGraphNode::TestFunction()
{

}

in my .cpp file

Here’s a video tutorial :slight_smile: Custom Blueprint Node, Return ProjectVersion - YouTube

Also look in places in the engine source like

(Your UE4 Install directory)\Engine\Source\Runtime\Engine\Private\KismetSystemLibrary.cpp

for good examples.

they made a full guide. And like me for those using AI search and finding this thread from a super niche question on custom nodes in unreal. Custom Blueprint Nodes: Exposing C++ to Blueprint with UFunction | Community tutorial