Ara you OK?
我看你是思想出现了偏差
哇!你认出了错别单词!恭喜你获得一次向我支付宝充值助我重返欧洲的机会!
这个页面管关不掉了,你自己看着办吧

UE4笔记-异步蓝图节点 (UBlueprintAsyncActionBase)

记录备查:

基于的UBlueprintAsyncActionBase类可实现异步蓝图节点

-------------------------------------------------------------------------------

例子:

.h

UCLASS()
class MYPROJECT_API UBPAsyncNode_Custom : public UBlueprintAsyncActionBase
{
    GENERATED_BODY()
public:
    DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FBPPin_Result, const TArray<FString>&, Datas);
    /** 输出针脚1 */
    UPROPERTY(BlueprintAssignable)
        FBPPin_Result OnSuccess;

    /** 输出针脚2 */
    UPROPERTY(BlueprintAssignable)
        FBPPin_Result OnFailure;
public:
    /** 蓝图节点:负责NewOBject 蓝图节点(创建工厂模式) */
    UFUNCTION(BlueprintCallable, meta = (BlueprintInternalUseOnly = "true", WorldContext = "WorldContextObject", Category = "Biz API"))
        static UBPAsyncNode_Custom* CustomAsyncBPNode(UObject* WorldContextObject);
protected:
    // UBlueprintAsyncActionBase interface


    /** 程序通过(运行)节点是调用 */
    virtual void Activate() override;

    //~UBlueprintAsyncActionBase interface

};

 

.cpp

UBPAsyncNode_Custom* UBPAsyncNode_Custom::CustomAsyncBPNode(UObject* WorldContextObject)
{
    UBPAsyncNode_Custom* Ins = NewObject<UBPAsyncNode_Custom>();
    return Ins;
}

void UBPAsyncNode_Custom::Activate()
{
    //测试逻辑----开新线程,延迟一秒后随机调用成功或失败委托
    Async(EAsyncExecution::ThreadPool, [&]()
        {
            FPlatformProcess::Sleep(1.0f);
            int32 result = FMath::RandRange(1,100);

            TArray<FString> arr;
            if (result > 50)
            {
                this->OnSuccess.Broadcast(arr);
            }
            else 
            {
                this->OnFailure.Broadcast(arr);
            }
        });
}

 

使用:

 

 

Note:

容器类类结果必须是

const  YourClass & 

如例子的TArray容器

 DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FBPPin_Result, const TArray<FString>&, Datas);

否则报错

Signature Error: XXXX  does not match the necessary signature 

 

posted @ 2020-07-30 17:30  林清  阅读(3975)  评论(0编辑  收藏  举报