Creating a new function from C++

Hey, I am currently trying to spawn a function graph within my UBlueprint. It works but when I compile that new graph I get this compile error message:

void UMyBlueprintFunctionLibrary::CreateFunctionGraphs()
{
    TSubclassOf<UEdGraphSchema> MySchema2 = UEdGraphSchema_K2::StaticClass();
    UEdGraph* EventGraph = CastChecked<UEdGraph>(FBlueprintEditorUtils::CreateNewGraph(GEngine, NAME_None, UEdGraph::StaticClass(), UEdGraphSchema_K2::StaticClass()));
    if (EventGraph) {
        EventGraph->Rename(*FString("EdGraph_0"));
        const UEdGraphSchema* Schema = EventGraph->GetSchema();
        Schema->CreateDefaultNodesForGraph(*EventGraph);
        GetBlueprintFromObject(GetSelectedBlueprint())->FunctionGraphs.Add(EventGraph);
        FBlueprintEditorUtils::MarkBlueprintAsStructurallyModified(GetBlueprintFromObject(GetSelectedBlueprint()));
        FKismetEditorUtilities::CompileBlueprint(GetBlueprintFromObject(GetSelectedBlueprint()));
    }
}

And indeed no such node spawns:
grafik
How do I spawn that Event/Node or how do I fix this error message?
My final goal is to create a function that simply spawns a new function as when you click on the + icon in the editor:
grafik

I found a solution! It wasnt straight forward but it works now and it makes sense now! :+1:

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