由於繼承自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 }
在藍圖中調用函數