I have a critical point in my code and I don’t like it.
It’s a horrible static hardcode full of literals in my Master Data Asset.
But without it is impossible (at least with my knowledge) to get an instance of the Master Asset.
UCLASS()
class UMasterDataAsset : public UPrimaryDataAsset
{
GENERATED_BODY()
UPROPERTY(EditAnywhere)
TArray<TSoftObjectPtr<UPrimaryDataAsset>> Assets;
static inline const FName PrimaryAssetTypeName = TEXT("Master");
static inline const FName FileName = TEXT("PDA_Master");
static inline const FString AssetPath = TEXT("/Game/DataAssets/PDA_Master.PDA_Master");
static inline const FPrimaryAssetId ID = FPrimaryAssetId(FPrimaryAssetType(PrimaryAssetTypeName) , FileName);
static const FSoftObjectPath& GetSoftObjectPath()
{
static const FSoftObjectPath Path(AssetPath);
return Path;
}
static UClientMasterAsset* Load()
{
UObject* Obj = GetSoftObjectPath().TryLoad();
return IsValid(Obj) ? Cast<UClientMasterAsset>(Obj) : nullptr;
}
}
I also tried this but I always get an empty list.
The list is not empty only after the assets have been loaded into memory (not before).
TArray<
FPrimaryAssetId>AssetIds;
UAssetManager::Get().GetPrimaryAssetIdList(FPrimaryAssetType(“Master”), AssetIds);
Any way to do this without hardcode?
Thank you so much!!