[5-0EA] PrimaryDataAsset not accessible for some reason (Kinda Resolved)

Hello the Community

I am using Primary Data Assets extensively and encountered weird behavior when trying to access them using C++. I don’t think C++ is to blame but I do have the issue in there.

I got 2 asset classes like this:

class XX UPDA_UniversalAssetBase : public UPrimaryDataAsset
class XX USpecializationDataAsset : public UPDA_UniversalAssetBase

I have an asset manager with a method to get the assets as a USpecializationDataAsset

TArray<UPDA_UniversalAssetBase*> UCultAssetManager::GetAssets(const FPrimaryAssetType& Type) const
{
	const UCultAssetManager& Manager = UCultAssetManager::Get();

	TArray<FPrimaryAssetId> IdList;
	TArray<UPDA_UniversalAssetBase*> AssetList;
	Manager.GetPrimaryAssetIdList(Type, IdList);

	UPDA_UniversalAssetBase* Asset = nullptr;
	
	
	for (const FPrimaryAssetId ID : IdList)
	{
		//Initialize
		Asset = nullptr;

		//get the value
		UObject* AssetObject = Manager.GetPrimaryAssetObject(ID);
		Asset = Cast<UPDA_UniversalAssetBase>(AssetObject);

		if(Type == SpecType)
		{
			UE_LOG(LogTemp, Display, TEXT("UCultAssetManager::GetAssets Spec &s"), Asset);
		}

		if(Asset == nullptr) continue;

		AssetList.Add(Asset);
	}
	return AssetList;

As you can see, I got the list of 6 assets:

I can get the object only for the first one, for some reason.

When I hit this line, it works for Index 0, and then it’s always nullptr.
UObject AssetObject = Manager.GetPrimaryAssetObject(ID);*

I do have a fix, but … I have to save the asset again. No modification whatsoever. Just save.
Here: It works. Now index 0 and 4 works, because I saved 4 …

Any idea what might be wrong ?

Thanks.

1 Like

If anyone has the samer issue, you may have to load your asssets manually like this:

UAssetManager& Manager = UCultAssetManager::Get();

TArray<FPrimaryAssetId> IdList;
TArray<UPDA_UniversalAssetBase*> AssetList;
Manager.GetPrimaryAssetIdList(Type, IdList);

//Load all assets anyway
Manager.LoadPrimaryAssets(IdList);

They are primary, so I shouldn’t have to. BUT have to.