Download

How to async load blueprint class derived from UPrimaryDataAsset?

Hello
I know how to create a pure Data Asset from this document https://docs.unrealengine.com/en-us/Engine/Basics/AssetsAndPackages/AssetManagement, but I don’t know how to async load a blueprint generated class derived from UPrimaryDataAsset. In the Asset Manager settings, I have set “Has Blueprint Classes”, but still got a null object after cast.



UCLASS(Abstract, BlueprintType)
class ACTIONRPG_API URPGAssembly : public UPrimaryDataAsset
{
    GENERATED_BODY()
public:
    /** Type of this item, set in native parent class */
    UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = Assembly)
        FPrimaryAssetType AssemblyType;

    /** Returns the logical name, equivalent to the primary asset id */
    UFUNCTION(BlueprintCallable, Category = Item)
        FString GetIdentifierString() const;

    /** Overridden to use saved type */
    virtual FPrimaryAssetId GetPrimaryAssetId() const override;
};

FString URPGAssembly::GetIdentifierString() const
{
    return GetPrimaryAssetId().ToString();
}

FPrimaryAssetId URPGAssembly::GetPrimaryAssetId() const
{
    // This is a DataAsset and not a blueprint so we can just use the raw FName
    // For blueprints you need to handle stripping the _C suffix
    return FPrimaryAssetId(AssemblyType, FName("BP_HS"));
}

UCLASS()
class ACTIONRPG_API URPGCharacterAssembly : public URPGAssembly
{
    GENERATED_BODY()
public:
    URPGCharacterAssembly()
    {
        AssemblyType = URPGAssetManager::CharacterAssemblyType;
    }
};




Async Load Asset node load failed too, why?

You should use “Get Class from Primary Asset Id” when using Blueprints as Primary Assets because you are actually making the class a primary asset, not a specific instance. Hope it helps!
I’m still working through this myself, I wonder if the note about stripping _C is relevant here?