ブループリント内で使うためのクラスは UBlueprintFunctionLibrary を継承します。
作成手順
ソースファイルの作成
コンテンツブラウザの右クリックメニューより[New C++ Class] を選択します。

[Blueprint Function Library] → [Next] を選択。

クラス名を命名し、公開・非公開クラスのいずれかを選択し[Create Class] で作成します。今回は Public クラスとしています。


ソースコードの編集
生成されたファイルの中身を確認し、ブループリントから呼び出したい関数を定義します。試しに静的関数を追加してみました。
#pragma once
#include "CoreMinimal.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "MyBlueprintFunctionLibrary.generated.h"
/**
*
*/
UCLASS()
class MYPROJECT_API UMyBlueprintFunctionLibrary : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
// 追加
UFUNCTION(BlueprintCallable, Category = "MyBlueprintFunctionLibrary")
static void Setup();
};
#include "MyBlueprintFunctionLibrary.h"
// 追加
void UMyBlueprintFunctionLibrary::Setup()
{
UE_LOG(LogTemp, Log, TEXT("called!!!"));
}
ここではSetup という関数を追加しています。内容はただデバッグログを出力するだけのものです。こちらかけたらコンパイルしておきます。
ブループリント で使う
作成したクラスを呼び出してみます。レベルブループリントを開き先ほど作成したクラスの関数(ノード)を検索すると出てきます。

結果
無事に関数が呼び出されました。
