Create blueprint asset file with C++

I was able to find a function that may help after digging around in the FKismetEditorUtilities:

   FAssetToolsModule& AssetToolsModule = FModuleManager::GetModuleChecked<FAssetToolsModule>("AssetTools");
	
	FString name = "testBlueprint";
	name = UPackageTools::SanitizePackageName(name);
	name = ObjectTools::SanitizeObjectName(name);
	FName fname = *name;

	FString packagePath = "/Game/Test/" + name;
	UPackage* OuterForAsset = CreatePackage(nullptr, *packagePath);

	UClass* BlueprintClass = nullptr;
	UClass* BlueprintGeneratedClass = nullptr;

	IKismetCompilerInterface& KismetCompilerModule = FModuleManager::LoadModuleChecked<IKismetCompilerInterface>("KismetCompiler");
	KismetCompilerModule.GetBlueprintTypesForClass(YourClassType::StaticClass(), BlueprintClass, BlueprintGeneratedClass);
	UBlueprint* newBlueprint = FKismetEditorUtilities::CreateBlueprint(YourClassType::StaticClass(), OuterForAsset, fname, BPTYPE_Normal, BlueprintClass, BlueprintGeneratedClass, FName("GeneratingBlueprintTest"));
    FAssetRegistryModule::AssetCreated(newBlueprint);
	FAssetEditorManager::Get().OpenEditorForAsset(newBlueprint);

    OuterForAsset->SetDirtyFlag(true);
    TArray<UPackage*> packagesToSave;
    packagesToSave.Add(OuterForAsset);
    FEditorFileUtils::PromptForCheckoutAndSave(packagesToSave, false, false);

For my case this works, it creates the asset, saves it, and opens up the blueprint window in editor upon creation, which is all I need. However, as a warning, I ran in to trouble when I tried to save the asset before opening up the blueprint window in editor.

2 Likes