Asset not found in AssetRegistry until I open it in editor

I am using the following code to find a particular asset in a test I am writing:

FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>(TEXT("AssetRegistry"));
IAssetRegistry& AssetRegistry = AssetRegistryModule.Get();
FAssetData CalmSeaOceanMaterialAsset = AssetRegistry.GetAssetByObjectPath(FName(TEXT("Material'/Game/Materials/Ocean/OceanDisplacementMaterials/SmallWaves.SmallWaves'")));

When I run this straight after starting the editor, CalmSeaOceanMaterialAsset contains an invalid reference. However, if I open the SmallWaves asset and then run this, it works as expected. Is this a bug/is there something I can do to force the object to be loaded before I try to find it in the AssetRegistry.

I am using UE4.4.1

I propose a tag “asset-registry” but don’t have high enough rep to create it.

Hi there! In the editor you might have to wait until the asset registry has finished discovering assets.

If AssetRegistry.IsLoadingAssets() returns true, you might have to come back later. Alternatively, you can bind onto its OnFilesLoaded() event to get notified when it has finished loading files.

EDIT:
This turned out to be failing due to the Material’’ type decoration that only succeeds when the asset is loaded. Passing in just the object path proved successful in both cases.

Thanks, unfortunately AssetRegistry.IsLoadingAssets() returns false but the asset is still not found.

Could you try changing it to just “/Game/Materials/Ocean/OceanDisplacementMaterials/SmallWaves.SmallWaves” without the extra UObject type decoration? When it is loaded, it will route through FindObject<> but when it has not been loaded yet, it needs to exactly match the object path that is stored in the asset registry map.

Thank you, this has fixed it if you want to update your answer to include the correct information :slight_smile: Is this documented somewhere I’ve missed?

Thanks, I updated the answer.
There’s some information here, but it doesn’t document the ObjectPath syntax explicitly. I’ll look to get this updated.