在UE4的UBlueprintFunctionLibrary子类中实现委托
由于继承自UBlueprintFunctionLibrary的子类中声明的函数基本上是static,
在类内部调用外部定义的委托编译时会报错,按如下方式进行操作则可正常使用。
*.h
1 UCLASS() 2 class UE4_OSS_LIBRARY_API UOSSApiUtilty : public UBlueprintFunctionLibrary 3 { 4 GENERATED_BODY() 5 public: 6 7 DECLARE_DYNAMIC_DELEGATE_TwoParams(FOssPutObjComplete, bool, IsSuccess, FString, Err); 8 9 UFUNCTION(BlueprintCallable, Category = "OSS_Api") 10 static void SetOssPutObjComplete(FOssPutObjComplete OnOssPutObjComplete); 11 12 static void OnOssPutObjComplete(bool IsSuccess, FString Err); 13 14 };
*.cpp
1 static UOSSApiUtilty::FOssPutObjComplete OssPutObjComplete;
2
3 void UOSSApiUtilty::SetOssPutObjComplete(FOssPutObjComplete OnOssPutObjComplete)
4 {
5 OssPutObjComplete = OnOssPutObjComplete;
6 }
7
8 void UOSSApiUtilty::OnOssPutObjComplete(bool IsSuccess, FString Err)
9 {
10 OssPutObjComplete.ExecuteIfBound(IsSuccess, Err);
11 }
在蓝图中调用函数