LoginSignup
0
0

More than 5 years have passed since last update.

Unreal Engine 4メモ:UFUNCTION()はオーバーロード出来ない

Last updated at Posted at 2018-01-19
sample1.cpp
UCLASS()
class AT_API ClassName
{
public:
    UFUNCTION(BlueprintCallable)
    void Function(int a, int b);

    UFUNCTION(BlueprintCallable)
    void Function(int a, int b, int c);
}
エラー
error : 'Function' conflicts with 'Function /Script/Project Name.ClassName:Function'

エンジンソースを見てみると下記のようになっています。

/UE4/UnrealEngine/Engine/Source/Programs/UnrealHeaderTool/Private/HeaderParser.cpp

1858: FError::Throwf(TEXT("'%s' conflicts with '%s'"), *ThisName.ToString(), *It->GetFullName() );

HeaderParserは非関数リストに新しい関数を追加する前に、既知の関数名をすべて列挙(iterate)する。
パラメータが何であっても、同じ名前のものがあればこのエラーがスローされます。
したがって、同じクラスに同じ名前の2つのUFUNCTIONSを持つことはできません。

UFUNCTION()はオーバーロード出来ないため、回避する必要があります。
他のスクリプト言語でもオーバーロード関数をバインドできなかったりするのでBPの仕様がそうなっているのでしょう。

sample2.cpp
UCLASS()
class AT_API ClassName
{
public:
    UFUNCTION(BlueprintCallable)
    void Function(int a, int b);

    UFUNCTION(BlueprintCallable)
    void FunctionWithC(int a, int b, int c); // 関数名を変える
}

参照:https://answers.unrealengine.com/questions/45623/function-declaration-with-the-same-name-with-diffe.html

0
0
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
0
0