Updating AssetRegistrySearchable properties at cook time

I have a scenario where I want to bake some metadata (gameplay tags) into an AssetRegistrySearchable property at cook time. I currently have these properties getting updated in both PreSave AND PostLoad which I thought would be good enough for the cooker but I’ve found a case where it appears not to pick up those metadata updates. I’m pretty confident the rest of the code is operating properly - I stepped through it in the cooker.

Do you have any other suggestions here?

Thanks!

[Attachment Removed]

Steps to Reproduce[Attachment Removed]

In 4.27, the AssetRegistry is mostly not updated during cooking. The data that is updated is updated in UCookOnTheFlyServer::UpdateAssetRegistryPackageData

. That function updates the FAssetPackageData with DiskSize and CookedHash, but it does not update any other data. The remaining data is copied from the editor’s version of the AssetRegistry that was loaded at the beginning of the cook.

The data you need that contains the information from the AssetRegistrySearchable UPROPERYs is the TagsAndValues on the FAssetData for each asset within the package. This data is calculated during the save of each cooked package, but it is not copied into the generated AssetRegistry.

The data is calculated in UE::AssetRegistry::WritePackageData in SavePackageUtilities.cpp. That function calls the appropriate functions to get the tags, and writes the FAssetData and tags into the package, without saving a copy of them to store in the AssetRegistry.

With various updates over the years in UE5, we have changed the behavior of SavePackage to store that data on the SavePackageResult, and copy it into the cooked AssetRegistry. The notable changes are

  • UE::AssetRegistry::WritePackageData now creates an array of FAssetData rather than serializing them directly into the package without making a copy.
  • There is a field on FSavePackageResultStruct names SavedAssets that receives these FAssetData. WritePackageHeader directs the output of WritePackageData first to an array on the FSaveContext object that is in scope during the save, and FSaveContext::GetFinalResult moves those FAssetData into the SavedAssets.
  • That array is eventually passed intoFAssetRegistryGenerator::StoreUpdateAssetRegistryData, which calls State.UpdateAssetData for each one.

You should be able to see all that code by looking at UE5/Main at head in the Unreal github. I think it should be fairly simple to copy the ideas from those changes that are relevant to saving and storing a copy of the recalculated FAssetData into your 4.27 branch.

[Attachment Removed]

Thanks Matt, this helps a bunch. I’ll have a look at this.

[Attachment Removed]