C++ ときどき ごはん、わりとてぃーぶれいく☆

USAGI.NETWORKのなかのひとのブログ。主にC++。

UE4: Blueprint 向けに提供する C++ 関数を pure に定義するメモ

1. AActor などの派生型でメンバー関数を pure にしたい場合

  • UFUNCTIONBlueprintCallable フラグを付けたメンバー関数を const 定義すれば自動的に blueprint でも pure になる。

2. UBlueprintFunctionLibrary 派生型の static メンバー関数を pure にしたい場合

  • UFUNCTIONBlueprintCallable フラグに加えて BlueprintPure フラグも付ける。
UCLASS()
class UMyUtility
  : public UBlueprintFunctionLibrary
{
  GENERATED_BODY()
public:
  UFUNCTION( BlueprintCallable, Category="My Utility", BlueprintPure )
  static bool AnyOf( const TArray< bool >& in );
};

bool UMyUtility::AnyOf( const TArray< bool >& in )
{
  for ( const auto v : in )
    if ( v )
      return true;
  return false;
}

f:id:USAGI-WRP:20180307062705p:plain

参考

だそく

Blueprint では const メンバー関数は自動的に pure で扱ってくれる。 static メンバー関数が非 pure で扱われる理由は無いのでわざわざ手打ちで BlueprintPure フラグを付けずとも static メンバー関数も自動的に pure で扱ってくれたらいいのに、と思った。理由は特に無くて気の利いた実装をまだ誰もそこに適用してPRする余力と関心が無いから、というだけな気もする。