x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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?

Thanks Bests YLi

Product Version: UE 4.20
Tags:
more ▼

asked Nov 06 '18 at 11:44 PM in C++ Programming

avatar image

Yli327
17 2 2 7

avatar image Shadowriver Nov 07 '18 at 10:06 PM

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

avatar image Yli327 Nov 08 '18 at 05:25 PM

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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

2 answers: sort voted first

Hi Yli327,

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.

more ▼

answered Nov 13 '18 at 08:23 PM

DarkwindRichard (suspended)
avatar image DarkwindRichard Nov 21 '18 at 03:08 PM

Hi Yli327,

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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Make UTexture2D* variable in C++ class, and ass 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

more ▼

answered Nov 08 '18 at 05:46 PM

avatar image

Shadowriver
35.9k 928 169 1105

avatar image Yli327 Nov 09 '18 at 11:00 PM

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?

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question