I’m currently trying to setup the asset manager via blueprint.
My setup:
PrimaryDataAsset “PDA_Item” in blueprint
Trying to overwrite GetPrimaryAssetId inside this blueprint, so the asset manager will notice it as a primary asset type
The function returns a struct of type PrimaryAssetId with PrimaryAssetType “Item” and PrimaryAssetName from variable “Name” that I set for every Asset of type “Item”
DataAsset “DA_Helmet” created from this PrimaryDataAsset
“Name” set to “Helmet”
Now trying to feed the asset to asset manager
Primay Asset Type “Item”
Asset Base Class “PDA_Item”
Has Blueprint Classes “checked”
Directories “…Content/Items”
However my assets don’t seem to be recognized by the asset manager. The blueprint node GetPrimaryAssetIdList returns an empty list for the PrimaryAssetType “Item”.
Has anyone experience with building this setup in blueprint? Is it even possible to overwrite GetPrimaryAssetId without C++?
What I’ve manged to do is to make them work all of them just fine. Problem is that they do not work with the Asset Manager. It doesn’t find the IDs so you can load them in batch. Which defeats the purpose of having them. I can load them one by one if I know where and how many of them to use. But that is not how it should work
It appears that you need to override the GetPrimaryAssetId() function, which you can use in code but not in blueprint.
I really don’t want to learn the ■■■■ C++ stuff. Now I’ve managed to create the primary data in code, then create the child data assets in blueprint. Works fine with the asset manager. As it should. But boy I can’t seem to create a struct, because all the blueprints structs I have are not visible in code.
edit: Nevermind, I’ve made it work. The asset manager finds the IDs, It appears I can avoid C++ for now.
yes, it works in blueprint mode only. with no C++. it takes some steps to have it work correctly, so please define what you want to do see if it match the system I’ve found
Since there is no mention of actual solution to this issue and I had to spend half day of debugging AssetManager and AssetRegistry code, here is how I managed to make it work:
Step 1:
Create a new Blueprint Class, derived from PrimaryDataAsset.
Lets give it a name PDA_Item.
Step 2:
Create some Data Asset(s) instances so we can test it. Make sure that it is derived from PDA_Item. Lets name it DA_Item01, DA_Item02…
Added via Content Browser->Right Click->Miscellaneous->Data Asset.
Step 3:
Go to Project Settings->Game->Asset Manager and then:
Add new entry to Primary Asset Types to Scan.
Set Asset Base Class to PDA_Item.
Set Primary Asset Type to to PDA_Item_C. ← Note _C.
Make sure Has Blueprint Classes is disabled.
Set directory where you stored your Data Assets eg. /Game/Items.
Step 4:
Now in BP you can use functionality such as:
Get Primary Asset Id List to obtain all asset Ids so you can load them via Async Load Primary Asset List.
Use Async Load primary Asset Class and be able to select from your primary asset ids.
Other UE / your own logic.
Step 5:
Now you can edit PDA files without any need to ask programmers to do it for you in C++.
Note:
If you change DA or Primary Asset Type names, you must fix references, since they will point to old ids/types.
Roman_Roba, you hero.
Adding the _C to the end of the Primary Asset Type, sorted my problem out.
Thank you for taking the time to share that solution breakdown
Throwing in my 2 cents here. The solution @Roman_Roba provided may work, but apparently there are issues with Blueprint inheritance when you mix BP classes & DataAsset instances.
The comment on UPrimaryDataAsset reads:
With blueprint subclasses, use Data Only Blueprints (and not Data Asset instances) to properly handle data inheritance and updating the parent class.
This is how it works:
Create a child BP of PrimaryDataAsset, e.g. BP_PawnDefinition.
→ This is your PrimaryAssetType
Create as many data-only child BPs of BP_PawnDefinition as you want.
→ These are your DataAssets, e.g. DA_PlayerPawn, DA_EnemyPawn, …
→ The name of these BP assets is your PrimaryAssetName.
→ Each asset now has a PrimaryAssetId like BP_PawnDefinition:DA_PlayerPawn
→ Apparently these BPs must be data-only and should not have any functions. Don’t know what happens otherwise.
Update your asset manager settings as follows.
→ Make sure that Has Blueprint Classes is checked!
Restart the editor. Now you can load these blueprints as primary data assets.
→ This is different from native DataAsset instances: Since Blueprints are technically classes and not objects, the usual “Async Load Primary Asset” node does not work.
→ Instead you have to load the class → cast the class → get class defaults to get at the data within your data-only BP asset, like so:
With the AssetManager in C++ you have to use UObject as a template parameter. Weirdly UPrimaryDataAsset will not work. I assume that also here it is being treated like a class and not an instance of UPrimaryDataAsset.
Hope this helps. If anyone knows of a better way let me know! Be aware that I haven’t tested this thoroughly, but this seems to be the way it’s supposed to work (?)
Edit: I’ve experimented with this some more. Absolutely do not do this if you intend to e.g. load a data-only BP asset in C++ and then pass it over to Blueprint. This only really works if you intend to load the asset in Blueprint.