I have a directory structure Game/Content/OldWest/VOL7/Meshes which contains uasset meshes. I am trying to load them dynamically through code (this is my first attempt). But I am unable to get the following code to load any UObjects. Any ideas, thanks?
The actual path for /Content is /Game, so you should replace β/Content/OldWest/VOL7/Meshes/β with β/Game/OldWest/VOL7/Meshes/β.
You can also do something like this to get all assets in a folder:
#include "LevelEditor.h"
#include "AssetRegistry/AssetRegistryModule.h"
#include "Engine/Blueprint.h"
// -------------
FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>("AssetRegistry");
IAssetRegistry& AssetRegistry = AssetRegistryModule.Get();
FARFilter Filter;
Filter.bRecursiveClasses = true;
Filter.bRecursivePaths = true;
// Get only Blueprint Assets
// You can modify this to get only StaticMesh or all the types you want if you want to filter it
Filter.ClassPaths.Add(UBlueprint::StaticClass()->GetClassPathName());
// Add your folder path
Filter.PackagePaths.Add("/Game/OldWest/VOL7/Meshes/");
// Get the assets and do stuff
TArray<FAssetData> AssetList;
AssetRegistry.GetAssets(Filter, AssetList);
for (const FAssetData& Asset : AssetList)
{
// Do stuff with the assets...
}
You can use Filter.ClassPaths.Add(UStaticMesh::StaticClass()->GetClassPathName()); to get Static Mesh assets, or at least that should work. You can also not specify any ClassPath and that should get all assets in the folder regardless of the type.