Searching for PrimaryDataAssets

Any help on this would be appreciated, I’ve been banging my head against my desk for a while now.

I’ve added a new PotionItem type for the asset manager to scan in my projects asset manager settings and then created two Potion assets in Items/Potions. I’m then trying to load all the Potion data assets, however GetPrimaryAssetIdList returns an empty array. Is there something obvious I’m missing to get the asset manager to find my assets?

Registered Asset Type

Sample Potion DataAssets (/Game/Items/Potions)

Debug (Print total/count assets)

I was having the same problem today and there’s a couple of similar threads on the forum with no replies. This thread is the first in Google, so I’ll leave an answer here.

The thing that you were doing wrong was the name “Potion” here:
image

Despite the appearance of the field, the name here can’t be arbitrary. In short, it must be in your case BP_PotionItem

The reason being, PrimaryDataAssets have a function called GetPrimaryAssetId().
That function returns its Primary Asset Type, and the field at the red arrow is also a Primary Asset Type, and the two must correspond. If you look at the engine code, the function returns its class name more or less. And so the class name is what you must type in here.
For more info on what exactly it returns in what cases, the snippet from the documentation:

Blueprint subclasses will end up with a PrimaryAssetType equal to the name of the first native class found going up the hierarchy, or the top level blueprint class that directly subclasses this.

If you have PrimaryDataAsset → ParentNativeClass → ChildNativeClass → BlueprintAsset the type will be ChildNativeClass
Whereas if you have PrimaryDataAsset → ParentBlueprintClass → ChildBlueprintClass the type will be ParentBlueprintClass
To override this behavior, override GetPrimaryAssetId in your native class

It took me a while, too, to figure out what they were talking about. If you need an example of overriding the GetPrimaryAssetId() function, you can find it in their Action RPG project.

1 Like