How to read color from texture by c++?

I need to load texture and read color. TSoftObjectPtr<UTexture2D> SectionBack = TSoftObjectPtr<UTexture2D>(FSoftObjectPath("/Game/Generators/Worlds/Worlds/Model/Textures/BackSegmentSurface_ncl1_1.BackSegmentSurface_ncl1_1"));
load it with UTexture2D* sectionBack = sectionBackPointer.LoadSynchronous();

use pointer to access const FColor* BackImageData = static_cast<const FColor*>(sectionBack->PlatformData->Mips[0].BulkData.LockReadOnly());
Next read it to array

FColor SectionBack[4096 * 4096];
SectionBack[y * sectionBack->GetSizeX() + x] = BackImageData[y * sectionBack->GetSizeX() + x];

and unlock bulk data

sectionBack->PlatformData->Mips[0].BulkData.Unlock();

everything compiled, but sectionBack->GetSizeX() returns 0
and color data is 0

How to make it read color from texture?

2 Likes

Not an expert. But try playing around with

SectionBack->SRGB = false;
SectionBack->UpdateResource();

before you call LockReadOnly. You may also want to play around with SectionBack->CompressionSettings

Related:

Accessing pixel values of Texture2D

How to read data from a UTexture2D in C++

1 Like

Problem was solved, method is right, but FColor have int values, not float, I’ve tried to read float value, so in debug I had zeroes