How do I add a node to a blueprint with C++

I’m writing an addon that will read from a file and add nodes to a Geometry Script Blueprint.
What is the command, with exact syntax for both .h and .cpp, #include files, and modules needed?
I’ve been digging for hours and can’t seem to find anything to use.

P.S. I’m not good at coding… which is why I use Geometry scripting & Geometry nodes in the first place. :wink:

After days of fumbling around I’m pretty sure this is the solution:

class UBlueprintNodeSpawner* Spawner;|

UK2Node_CallFunction NodeClass;|
NodeClass.SetFromFunction();|
Spawner->NodeClass = NodeClass;

But “setFromFunction” requires a “UFUNCTION” variable, and I have no idea the syntax to pass that through.

Say, for example the Ufunction I want to spawn is “static UBlueprint* CreateBlueprint”, what’s the syntax? I’ve tried just the function name, with quotes, with &&, etc.

and

Oh, had to #include “UObject/Class.h” to pass UFunction as argument.

Pretty sure I’ve got it narrowed down to:
void UMakeBlueprintNodeBPLibrary::AddNodeToBlueprint(UEdGraph* Graph)
{
UFunction* Reference;
Reference->FindFunction(“Create Blueprint”);
class UBlueprintFunctionNodeSpawner* Spawner;
Spawner = Spawner->Create(Reference, nullptr);
FVector2D Slerp;
Slerp.Set(0.f, 0.f);
TSet<FBindingObject,DefaultKeyFuncs<FBindingObject,false>, FDefaultAllocator> Derp;
Spawner->Invoke(Graph, Derp, Slerp);
}

The problem now: Invoke requires “bindings”, and I haven’t got the slightest clue how to create/set/pass this to the function.

by node, are you looking for adding a new function into blueprint? because in that case, id recommend you create a plugin with the type of blueprint function library. its a pretty simple setup operation, and unreal handles most of the stuff for you.
id also recommend taking a look at other peoples plugins (or the engine code) to see what they are doing. a simple plugin with one .h and one .cpp file would probably be a ideal to work with.

There are no addons that add nodes to blueprints, that I can find.

“its a pretty simple setup operation” -_- If it were simple I’d have it done already. I’m on hour #38 trying to simply add a node to an event graph. Frustration abounds.

Clarification: Not trying to make a function “blueprint callable”, I’m trying to add a callable function node to a graph.

Useful:
Exact syntax
Or link to example

Not helpful: “It’s simple”.

i wasnt sure what you were wanting specifically because of the way you worded it, so thats why i didnt provide any example code; it would be quite a a waste of work to creat some code that you arnt going to use (case in point this exact situation). you already know how to make a function blueprint callable it seems, so my provided code would be useless for your situation.

as for your specific question, im not totally sure how to help unfortunately, now that i better understand it

Well, thanks for taking the time. I’ve already logged 48+ hours for bashing my face into a wall just to add a node to a graph. I think it’s time to hope on fivr, and see if I can get someone to help.

what is the exact thing you are trying to do? i may know it by a different name. do you have a reference picture perhaps?

You know how you Right click on a graph, and select a node, and that node is added to the graph?
I’m trying to call the function that adds the selected “function node” to the graph.

I’m pretty sure it’s “UBlueprintFunctionNodeSpawner::Create(TSubclassOf<UK2Node_CallFunction> NodeClass, UFunction const* const Function, UObject* Outer/* = nullptr*/)”

To create the “node spawner” and

UBlueprintFunctionNodeSpawner::Invoke(UEdGraph* ParentGraph, FBindingSet const& Bindings, FVector2D const Location) const

To actually spawn the node on the graph.

The two parts of the syntax I don’t understand:
the “UFunction” variable, how do I set it to the function I want, like “Add Triangle to Mesh”?
And “Bindings” variable, I can’t figure out what I’m supposed to pass (and how)

Ok. Gave up and added this to Fiverr, if anyone wants to make a quick buck. Under title “Create Unreal Addon Base”.

Funny Story: I had Chat GPT Fix it:

UEdGraphNode* UMakeBlueprintNodeBPLibrary::AddNodeToBlueprint3(UBlueprint* Blueprint, FName FunctionName, UClass* Class, FVector Location)
{
if (!Blueprint)
{
// Blueprint is null, handle the error
return nullptr;
}

if (!Class)
{
	// The blueprint class is null, handle the error
	return nullptr;
}

UFunction* Function = Class->FindFunctionByName(FunctionName);
if (!Function)
{
	// The function does not exist in the blueprint class, handle the error
	UE_LOG(LogTemp, Warning, TEXT("Function Not Found"));
	return nullptr;
}

// Get the Event Graph of the blueprint
UEdGraph* EventGraph = Blueprint->UbergraphPages[0];

// Create a new function node in the Event Graph
UEdGraphNode* NewNode = NewObject<UEdGraphNode>(EventGraph);


UBlueprintFunctionNodeSpawner* FunctionNodeSpawner = UBlueprintFunctionNodeSpawner::Create(Function);
if (FunctionNodeSpawner)
{
	FunctionNodeSpawner->SetFlags(RF_Transactional);
	NewNode = FunctionNodeSpawner->Invoke(EventGraph, IBlueprintNodeBinder::FBindingSet(), FVector2D(Location.X, Location.Y));
	return NewNode;
}

return nullptr;

}

1 Like