How to get a list of assets from code?

You could use the asset registry to do this. This won’t actually load the assets, so you can lazy load them if you need to.

FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>(FName("AssetRegistry"));
IAssetRegistry& AssetRegistry = AssetRegistryModule.Get();

// Need to do this if running in the editor with -game to make sure that the assets in the following path are available
TArray<FString> PathsToScan;
PathsToScan.Add(TEXT("/Game/Assets/Meshes/"));
AssetRegistry.ScanPathsSynchronous(PathsToScan);

TArray<FAssetData> MeshAssetList;
AssetRegistry.GetAssetsByPath(FName("/Game/Assets/Meshes/"), MeshAssetList);

Alternatively you can do the following, which will load all the assets in the path immediately and then return you them.

TArray<UObject*> MeshAssets;
EngineUtils::FindOrLoadAssetsByPath(TEXT("/Game/Assets/Meshes/"), MeshAssets, EngineUtils::ATL_Regular);

You’ll need to make sure the assets in that path get cooked by adding them to the “Additional Asset Directories to Cook” in your project packaging settings.

1 Like