5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[UE4] 関数を文字列で呼び出して実行する

Posted at

UE4 は様々なリフレクション的コードを自動生成し、それを利用して Blueprint の実行やオブジェクトのロードなどが行われています。

今回はこの仕組を利用して、C++コードで関数を文字列で呼び出してみます。

リフレクションコードの生成

リフレクションコードを生成させるには、 UCLASS(...)UFUNCTION(...) マクロを利用します。

UCLASS()
class FunctionTest: public UObject
{
    GENERATED_BODY()

protected:
    UFUNCTION()
    void CallableFunction(const FString& arg0)
    {
        UE_LOG(LogTemp, Log, TEXT("CallableFunction: %s"), *arg0);
    }
};

リフレクションを使って呼び出し

auto Obj = NewObject<FunctionTest>();
FName FuncName = TEXT("CallableFunction");
check(Obj);
auto FuncDelegate = TBaseDelegate<void, const FString>::CreateFunction(Obj, FuncName);
FuncDelegate.ExecuteIfBound(TEXT("hogehoge"));

デバッグ用機能などで便利かもしれない。

5
2
0

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
5
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?