Hello,
I’ve been wrestling with async loading of assets for some time now, and I am 80% of the way there. I declared the following data asset class:
UCLASS(BlueprintType)
class UCharacterDescriptor : public UPrimaryDataAsset
{
GENERATED_BODY()
public:
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly)
FName NameId;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly)
FText DisplayName;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, meta = (AssetBundles = "Scene"))
TSoftObjectPtr<class USkeletalMesh> BaseMesh;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, meta = (AssetBundles = "Scene"))
TSoftClassPtr<class UAnimInstance> AnimClass;
UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, meta = (AssetBundles = "UI"))
TSoftObjectPtr<class UTexture2D> PortraitThumbnail;
};
Somewhere in code, I hold a TSoftObjectPtr<UCharacterDescriptor>
property. I successfully async load that using:
auto primaryAssetId = assetMgr.GetPrimaryAssetIdForPath(charDescriptor.ToSoftObjectPath());
if(primaryAssetId.IsValid())
{
TArray<FName> bundlesToLoad; // Load everything, since scene will ultimately need both UI and Scene display
m_characterAssetsHandle = assetMgr.LoadPrimaryAsset(primaryAssetId, bundlesToLoad, FStreamableDelegate::CreateUObject(this, &AMyPawn::OnCharacterAssetsLoaded));
}
In the callback, I do get a valid UCharacterDescriptor, however I was under the impression that async loading a primary asset will also load all secondary assets within. My TSoftObjectPtrs for the mesh and anim resource are still null.
My question is: Should the data asset be holding a raw pointers to the properties - if so, will they still be loaded asynchronously, or will they force some kind of flush that leads to a sync load?
Or should I hold a raw pointer to the data asset instead of a TSoftObjectPtr, and keep the properties within as soft references.
Facing this limitation, I am struggling to see why would I use the UAssetManager
as opposed to the FStreamableManager
.