I have a project which requires the thumbnail textures of various static meshes (there are more than 300 of them).
After experimenting with various runtime methods of doing this dynamically, I finally decided the best route is probably to create an editor plugin which utilizes FAssetRegistryModule
to listen for whenever an FAssetData
entry has been added. I have done this successfully, like so:
UMyAssetManager::UMyAssetManager()
{
TargetPath = TEXT("/Meshes/");
FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>("AssetRegistry");
AssetRegistryModule.Get().OnAssetAdded().AddUObject(this, &UMyAssetManager::OnAssetAdded);
}
UMyAssetManager::~UMyAssetManager()
{
FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>("AssetRegistry");
AssetRegistryModule.Get().OnAssetAdded().RemoveAll(this);
}
void UMyAssetManager::OnAssetAdded(const FAssetData& AssetData)
{
auto assetName = AssetData.GetFullName();
auto assetClass = AssetData.AssetClass;
if (assetName.Contains(TargetPath) && assetClass.IsEqual(TEXT("StaticMesh")))
{
auto assetRef = AssetData.ToStringReference();
// Do something with this asset reference here...
// ...(for example, load & cache it into an array, like below)
FStreamableManager AssetLoader;
auto Asset = AssetLoader.SynchronousLoad(assetRef);
if (Asset && Asset->IsValidLowLevel()) {
Meshes.AddUnique(CastChecked<UStaticMesh>(Asset));
}
}
}
So now that, with the code above, we can know when each individual mesh is added to the content browser, all I need is a way to access the FAssetData
's thumbnails. Does anybody know how this can be achieved?