# How to read color from texture by c++?

**URL:** <https://forums.unrealengine.com/t/how-to-read-color-from-texture-by-c/582765>\
**Category:** C++\
**Tags:** unreal-engine, UE5-0, Code, CPP, question\
**Created:** [June 15, 2022, 5:04pm UTC](https://forums.unrealengine.com/t/how-to-read-color-from-texture-by-c/582765 "2022-06-15T17:04:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MasterOfDreams](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MasterOfDreams](https://forums.unrealengine.com/u/MasterOfDreams)\
**Post date:** [June 15, 2022, 5:04pm UTC](https://forums.unrealengine.com/t/how-to-read-color-from-texture-by-c/582765/1 "2022-06-15T17:04:21Z")

</div>

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

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

```

and unlock bulk data

```auto
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?

---

<div class="post-metadata">

**Author:** ![FloodAnxiety](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@FloodAnxiety](https://forums.unrealengine.com/u/FloodAnxiety)\
**Post date:** [June 17, 2022, 7:56pm UTC](https://forums.unrealengine.com/t/how-to-read-color-from-texture-by-c/582765/2 "2022-06-17T19:56:56Z")

</div>

> [@MasterOfDreams](#):
>
> UTexture2D

Not an expert. But try playing around with

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

```

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

---

<div class="post-metadata">

**Author:** ![Roy\_Wierer.Seda145](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/roy_wierer.seda145/32/906551_2.png) [@Roy\_Wierer.Seda145](https://forums.unrealengine.com/u/Roy_Wierer.Seda145)\
**Post date:** [June 17, 2022, 11:13pm UTC](https://forums.unrealengine.com/t/how-to-read-color-from-texture-by-c/582765/3 "2022-06-17T23:13:23Z")

</div>

Related:

> [Accessing pixel values of Texture2D](https://forums.unrealengine.com/t/accessing-pixel-values-of-texture2d/279798)

> [How to read data from a UTexture2D in C++](https://stackoverflow.com/questions/37578939/how-to-read-data-from-a-utexture2d-in-c)

---

<div class="post-metadata">

**Author:** ![MasterOfDreams](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MasterOfDreams](https://forums.unrealengine.com/u/MasterOfDreams)\
**Post date:** [June 26, 2022, 7:37am UTC](https://forums.unrealengine.com/t/how-to-read-color-from-texture-by-c/582765/4 "2022-06-26T07:37:18Z")

</div>

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
