Can't make function Blueprint callable

I can’t get make a custom blueprint node to save my life.

It should be as simple as:
#include “Kismet/BlueprintFunctionLibrary.h”
UFUNCTION(BlueprintCallable)
static UBlueprint* CreateBlueprint(FString BlueprintPath, TSubclassOf ParentClass, bool& bOutSuccess, FString& OutInfoMessage);

And tried:
UFUNCTION(BlueprintPure, meta = (DisplayName = “Adds floats”, CompactNodeTitle = “Add Floats”, Keywords = “Float Add”), Category = Game)
static float AddFloats(float fA, float fB);

And dozens of other variations from tutorials. It simply won’t show up. I’ve rebuilt each time, tried live coding, tried shutting down and restarting editor… Just refuses to add a custom node.

Help please. 12 hours just trying to make a simple node appear on a graph. -_-

is it after a public: declaration?

Tried without Public:
And After Public:

#pragma once

#include “CoreMinimal.h”
#include “Kismet/BlueprintFunctionLibrary.h”
#include “CreateBlueprint.generated.h”

/**
*
*/
UCLASS()
class GEONODESTOGEOSCRIPT_API UCreateBlueprint : public UBlueprintFunctionLibrary
{
GENERATED_BODY()

public:

UFUNCTION(BlueprintCallable, Category="NodesToScript")
	static UBlueprint* CreateBlueprint(FString BlueprintPath, TSubclassOf<UObject> ParentClass, bool& bOutSuccess, FString& OutInfoMessage);

};

You have an error in your syntax.

TSubclassOf takes in a parameter like TSubclassOf

Your code shouldn’t compile

That’s just a HTML display bug related to Brackets
Look at the whole code pasted above.

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

#pragma once

#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "CreateBlueprint.generated.h"

/**
 * 
 */
UCLASS()
class YOUR_API UCreateBlueprint : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()

public:
		UFUNCTION(BlueprintCallable, Category = "NodesToScript")
		static UBlueprint* CreateBlueprint(FString BlueprintPath, TSubclassOf<UObject> ParentClass, bool& bOutSuccess, FString& OutInfoMessage);
};

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


#include "CreateBlueprint.h"

UBlueprint* UCreateBlueprint::CreateBlueprint(FString BlueprintPath, TSubclassOf<UObject> ParentClass, bool& bOutSuccess, FString& OutInfoMessage) 
{

	//TSubclassOf<class UBlueprint> targetBP;

	static ConstructorHelpers::FObjectFinder<UBlueprint> myBlueprint(*BlueprintPath);		
	UBlueprint* targetBP = myBlueprint.Object; //->GeneratedClass;
 	
	return targetBP;
}

Shows up no problem but static ConstructorHelpers::FObjectFinder can’t be used outside of a constructor and it crashes the engine. A lazyload would work but it needs a softpointer :confused:

I’m not spawning anything in the world.

The function creates a blueprint… but I haven’t gotten far enough to test the function… because I can’t get the function to even appear as a node in blueprints.

Ok found a kismet function that already does this

/** Create a new Blueprint and initialize it to a valid state. */
UBlueprint* FKismetEditorUtilities::CreateBlueprint(UClass* ParentClass, UObject* Outer, const FName NewBPName, EBlueprintType BlueprintType, TSubclassOf<UBlueprint> BlueprintClassType, TSubclassOf<UBlueprintGeneratedClass> BlueprintGeneratedClassType, FName CallingContext)
{
/// code
}

It’s inside of

So, trying the same thing over and over, I finally got an empty function to show up in the library.

Still can’t get the full function to show up. But, at least I get an error now while “live loading”. No error in VS… but CTR->Alt->F11 to compile in UE gives a link error.

error LNK2019: unresolved external symbol “__declspec(dllimport) public: static bool __cdecl FKismetEditorUtilities::CanCreateBlueprintOfClass(class UClass const *)”

In .cpp:
#include “NewBlueprintFunctions.h”
#include “AssetRegistry/AssetRegistryModule.h”
#include “KismetCompilerModule.h”
#include “Kismet2/KismetEditorUtilities.h”

in Build.cs:
PrivateDependencyModuleNames.AddRange(
new string[]
{
“Projects”,
“InputCore”,
“EditorFramework”,
“UnrealEd”,
“ToolMenus”,
“CoreUObject”,
“Engine”,
“Slate”,
“SlateCore”,
“AssetRegistry”,
“KismetCompiler”,
// … add private dependencies that you statically link with here …
}
);
KismetEditorUtilities are part of Module UnrealEd.

Hahah… That’s exactly the function I’m trying to make a node out of. Just doing some error checking before calling it to make sure it doesn’t crash.

Following guide from:
UE5 C++ 12 - How To Create Blueprint Asset with C++? - Unreal Engine Tutorial Editor CPP - YouTube.

BTW: Thanks so much for taking the time to try and help. It really is greatly appreciated.

Got it working no problems.

.h

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

#pragma once

#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "CreateBlueprint.generated.h"

/**
 * 
 */
UCLASS()
class SWAPYOUR_API UCreateBlueprint : public UBlueprintFunctionLibrary
{
	GENERATED_BODY()

public:
		UFUNCTION(BlueprintCallable, Category = "NodesToScript")
		static UBlueprint* CreateBlueprint(FString BlueprintPath, TSubclassOf<UObject> ParentClass, bool& bOutSuccess, FString& OutInfoMessage);
};

cpp

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


#include "CreateBlueprint.h"
#include "Kismet2/KismetEditorUtilities.h"
#include "KismetCompilerModule.h" 
#include "AssetRegistry/AssetRegistryModule.h"

UBlueprint* UCreateBlueprint::CreateBlueprint(FString BlueprintPath, TSubclassOf<UObject> ParentClass, bool& bOutSuccess, FString& OutInfoMessage) 
{		
	if (StaticLoadObject(UObject::StaticClass(), nullptr, *BlueprintPath) != nullptr) {
		bOutSuccess = false;
		OutInfoMessage = FString::Printf(TEXT("Create Blueprint Failed - An asset already exists at that location. '%s'"), *BlueprintPath);
		return nullptr;
	}

	if (!FKismetEditorUtilities::CanCreateBlueprintOfClass(ParentClass)) {
		bOutSuccess = false;
		OutInfoMessage = FString::Printf(TEXT("Create Blueprint Failed - Parent class is not blueprintable '%s'"), *BlueprintPath);
		return nullptr;
	}

	UPackage* Package = CreatePackage(*BlueprintPath);
	if (Package == nullptr) {
		bOutSuccess = false;
		OutInfoMessage = FString::Printf(TEXT("Create Blueprint Failed - Failed to create asset package. Make sure path is valid '%s'"), *BlueprintPath);
	}


	UClass* BpClass = nullptr;
	UClass* BpGenClass = nullptr;
	FModuleManager::LoadModuleChecked<IKismetCompilerInterface>("KismetCompiler").GetBlueprintTypesForClass(ParentClass, BpClass, BpGenClass);

	UBlueprint* Blueprint = FKismetEditorUtilities::CreateBlueprint(ParentClass, Package, *FPaths::GetBaseFilename(BlueprintPath), BPTYPE_Normal, BpClass, BpGenClass);

	FAssetRegistryModule::AssetCreated(Blueprint);
	Blueprint->MarkPackageDirty();

	bOutSuccess = true;
	OutInfoMessage = FString::Printf(TEXT("Create Blueprint Succeeded '%s'"), *BlueprintPath);
	return Blueprint;

}

in build

PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" });

PrivateDependencyModuleNames.AddRange(new string[] { "UnrealEd", "KismetCompiler", "AssetRegistry" });

Make sure you are in an Editor Utility Widget or other variations of the Editor Utility.

You can’t be in a normal widget or actor blueprint.

Direct copy and paste and still get error:
error LNK2019: unresolved external symbol "__declspec(dllimport) public: static class UBlueprint * __cdecl FKismetEditorUtilities::CreateBlueprint

I’ll start from scratch… again. Keep doing the exact same thing… and somehow I’m closer than when I started… but still not as close as when someone else does the exact same thing. -_-

Thanks. Will worry with it tomorrow.

Try deleting temp folders
Intermediate
saved
DerivedCache
.vs
Binaries
And regenerate the project.

Also make sure to set your _API in the library header

I understand the first part, but not the “regenerate project”. How do I do that?

Ok, Got it to work in a brand new project.

So, something wrong with my current one. I think I can take it from here (every if I have to use a new project… nothing really in the current one)

Deleting those folders wrecked the project entirely. Unsalvagable.
Rebuild failed, “Solution” file broken, editing the .cpp files directly had no effect.

Luckily, not a big deal, as it was a scratchpad project.

Started new project, everything works. Creates the BP as expected. Now I just have to figure out the C++ command to add nodes to exist blueprints. :upside_down_face:

the solution file can also be deleted (*.sln) it is regenerated in the process.
I’ve done this hundreds of times and can do do it in my sleep at this point

  • .vs
  • binaries
  • saved
  • Intermediate
  • DerivedDataCache

the sln file
the .vsconfig file

I’ve been building projects for over 8 years at this point.

Never delete the following

  • Source (this is where your c++ files live)
  • Content (your game folder)
  • Config
  • Platforms
    your main Uproject file needed for regeneration

Make sure that at any time you are creating any .cpp or .h files that they aren’t saved into Intermediate by accident!.

It can be a common error of inexperienced coders that don’t notice visual studio saving there.

Intermediate is a temp directory and none of your project files header or cpp should be there. Their place is in source.

“I’ve done this hundreds of times and can do do it in my sleep at this point”
This speaks volumes. It’s really sad their system is so buggy that this is an actual thing.

I go back and forth between having 10,448 errors (in a brand new file), to 14… and it runs fine with the 14. When it has 10k+ I can’t even function. Intellisense just breaks and I have no idea what to type. :frowning: Or what I do that makes them magically vanish…