How/where to write a custom BP node in C++?

I want to create a BP node that gets all keys from a blackboard.

So I found this online:

https://www.reddit.com/r/unrealengine/comments/orz88s/get_all_keys_from_blackboard/

But I have no idea where to put that code, if I need some software to compile and save a file, or if I just dump that code into the editor, or to some sort of config file in UE.

How to do so?

you can make a function library in C++, then you can use those functions anywhere in your project. its not too hard to work with as unreal engine sets it all up for you. heres some basic code to get you started.

Header file

UCLASS(BlueprintType, Category = "categoryName")
class UYourClassName : public UBlueprintFunctionLibrary
{

	GENERATED_BODY()

public:

	UFUNCTION(BlueprintCallable, BlueprintPure)
	void GetAllBBKeys(TArray<FName>& OutKeys) const;

};

C++ file


void UYourClassName::GetAllBBKeys(TArray<FName>& OutKeys) const
{ 
    const TArray<FBlackboardEntry>& Keys = Blackboard->GetBlackboardAsset()->GetKeys();

    for (const FBlackboardEntry& Key : Keys)
    {
	    OutKeys.Add(Key.EntryName);
    }

}

Youll also need visual studio. Heres a guide on how to get that setup Setting Up Visual Studio for Unreal Engine | Unreal Engine 4.27 Documentation

Note i havent actually tested this, but that should atleast get you started.
also, you may have issues with hot realoding your code. if you do, try restarting the editor, or running it directly from visual studio.

1 Like

Hey, thanks for replying

I have visual studio installed, and I’ve been through that setup, it should be working fine, but I don’t know where or how to save that code you posted.

So I started new .h and .cpp files in visual studio and typed that code you mentioned. Edited the names to my like and now do I just save those files? where? and how do I access them in UE?

you make a new C++ class in unreal engine. it will handle all the setup and boilerplate stuff for you. you can set it to be any of class (actor for example), but if you do youll have to make a child of that class in order to use the function. making it a function library or blugin will make it class agnostic which seems like what you want (ie, you’ll be able to use it anywhere in your project). id recommend plugin over bleuprint function library, as plugins can be easily pulled into other projects
im in unreal 4.27, but it should be a similar process in unreal 5+

Heres how to make a function library

heres how to make a function library plugin