• 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 

  • 相关阅读:
    c++字符串
    iOS调用相册
    cocos2d-x中有一个JniHelper类详细使用
    iOS 字符串应用
    c++调用java
    iOS调用相册、相机、上传等问题
    win32中GBK、UTF8的互转
    SQL Server海量数据查询代码优化建议
    JSON中的[]和{}
    数据库范式
  • 原文地址:https://www.cnblogs.com/linqing/p/13405210.html
Copyright © 2020-2023  润新知