Hello, Could you please tell me how to retrieve the Texture data from asset in c++?

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?


what kind of data, pixel data? or you want to get UTexture (which is asset btw)?

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++.

Make UTexture2D* variable in C++ class, and ■■■ EditAnyware or EditDefaultsOnly in to UPROPERTY() like this:

UPROPERTY(EditAnywhere, Category="Some Category")
UTexture2D* MyTexture

Then make blueprint based of that class and in defults you can set the texture which if you se you will be able to access

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?

Hi ,

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

// 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.

Hi ,

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.