LoginSignup
0

More than 5 years have passed since last update.

戻り値のあるブループリント関数を CreateEvent ノードで指定できるようにする際の注意点

Posted at

この記事の補足記事です。

「戻り値のあるブループリント関数が Create Event ノードで列挙されなかった」

と言った現象が発生したので、調べてみました。

現象について

例えば、C++ で「戻り値のある動的デリゲータを引数として受け取る関数」を以下のように定義します。
(ここでは「MyFunc」という名前にします。)

// bool を返すデリゲータ
DECLARE_DYNAMIC_DELEGATE_RetVal(bool, FExecuteDelegate);

/**
 * 
 */
UCLASS()
class MYPROJECT_API UMyBlueprintFunctionLibrary : public UBlueprintFunctionLibrary
{
    GENERATED_BODY()

    // bool を返すデリゲータを引数として受け取る
    UFUNCTION(BlueprintCallable, Category = "MyProject")
    static void MyFunc(FExecuteDelegate Event) {}

};

そして、定義した「MyFunc」を使って、ブループリントで以下のようなノードを組みます。
DelegateFunc2.png

次に、「Create Event ノード」で指定するための「bool を返す関数」をブループリントで定義します。
(ここでは、「DelegateFunc」という名前にします。)
DelegateFunc.png

これで「Create Event ノード」「DelegateFunc」を指定することが出来ると思ったのですが……。
DelegateFunc3.png

見ての通り、「DelegateFunc」が列挙されませんした。

対処法について

そこで調べてみたところ、デリゲータの定義を以下の様に変更すれば出来ると書かれていたので、試してみました。

// bool を返すデリゲータ
//DECLARE_DYNAMIC_DELEGATE_RetVal(bool, FExecuteDelegate);
DECLARE_DYNAMIC_DELEGATE_OneParam(FExecuteDelegate, bool&, Output); //<-- これ

/**
 * 
 */
UCLASS()
class MYPROJECT_API UMyBlueprintFunctionLibrary : public UBlueprintFunctionLibrary
{
    GENERATED_BODY()

    // bool を返すデリゲータを引数として受け取る
    UFUNCTION(BlueprintCallable, Category = "MyProject")
    static void MyFunc(FExecuteDelegate Event) {}

};

結果はどうなったかというと……
DelegateFunc4.png

無事に「DelegateFunc」を指定できるようになりました。

参考サイト

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0