Hi, Guys,
I know one asset may have multiple textures, I want to retrieve all textures information of the asset and verify their data. I think I need to use the UTexture, but I do not know how to get them from the asset, Could you please teach me about that?
Hi, I just wanna retrieve the Texture resolution and whether the texture uses the sRGB channel, some information like that in the C++. Could you please tell me how to get them? I have the texture file in the folder and is used by the asset(blueprint class). So I just wanna get the texture information from these actors or assets in C++.
Thank you for your help, but I want to access the texture without using the blueprint and just use the C++ code except iterating all the texture files in the folder, is that possible?
If you wish to search a specific folder for all textures inside of it, then you can use the AssetRegistry to do so. Here is a small example:
// Get the asset registry module
FAssetRegistryModule& AssetRegistryModule = FModuleManager::LoadModuleChecked<FAssetRegistryModule>("AssetRegistry");
IAssetRegistry& AssetRegistry = AssetRegistryModule.Get();
// Create the filter
FARFilter AssetRegistryFilter;
AssetRegistryFilter.bRecursiveClasses = true;
AssetRegistryFilter.bRecursivePaths = true;
AssetRegistryFilter.PackagePaths.Add("/Game"); // Change this to the path to the folder
AssetRegistryFilter.ClassNames.Add(UTexture::StaticClass()->GetFName());
// Search the registry
TArray<FAssetData> FilteredAssetData;
if (AssetRegistry.GetAssets(AssetRegistryFilter, FilteredAssetData))
{
for (const FAssetData &AssetData : FilteredAssetData)
{
if (UTexture *Texture = Cast<UTexture>(AssetData.GetAsset()))
{
if (Texture->SRGB)
{
UE_LOG(LogTemp, Log, TEXT("%s is an sRGB texture!"), *AssetData.ObjectPath.ToString());
}
}
}
}
Note, though, that this will require you to add a dependency (public or private) to AssetRegistry.
We haven’t heard from you in a while so I’m going to mark this question as resolved. Based on your comment “I want to access the texture without using the blueprint and just use the C++ code except iterating all the texture files in the folder”, I am going to select this as the answer. If this does not solve your issue or you wish yo re-open the question for another reason, feel free to add a comment.