UE4: Blueprint 向けに提供する C++ 関数を pure に定義するメモ
1. AActor
などの派生型でメンバー関数を pure にしたい場合
UFUNCTION
でBlueprintCallable
フラグを付けたメンバー関数をconst
定義すれば自動的に blueprint でも pure になる。
2. UBlueprintFunctionLibrary
派生型の static メンバー関数を pure にしたい場合
UFUNCTION
でBlueprintCallable
フラグに加えて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; }
参考
だそく
Blueprint では const
メンバー関数は自動的に pure で扱ってくれる。 static
メンバー関数が非 pure で扱われる理由は無いのでわざわざ手打ちで BlueprintPure
フラグを付けずとも static
メンバー関数も自動的に pure で扱ってくれたらいいのに、と思った。理由は特に無くて気の利いた実装をまだ誰もそこに適用してPRする余力と関心が無いから、というだけな気もする。