Getting UTexture raw pixel data


Can someone hint me how I can get raw pixel data from the UTexture I retreive from a material?

I am stuck at the point where I need to get actual pixel data I have no idea where to get documentation for it, because in official docs there is not any mention about that.

Any ideas?

Hi I had this code that writes to a texture

void* TextureData = NewTexture->PlatformData->Mips[0].BulkData.Lock(LOCK_READ_WRITE);//locking the data since it is multi threaded
FMemory::Memmove(TextureData, PixelData.GetData(), PixelData.Num() * sizeof(uint8));

I think you can use it for reading. Use LOCK_READ and change order in memmove arguments.

Unfortunatly PlatformData is not a member of UTexture, it is a member of UTexture2D Though. The problem is that I dont see any point casting UTexture to UTexture2D to access PlatformData. Do you have any other Ideas? Please I beg you cause I am stuck and have no more ideas how I can acomplish this.

You can access Resource variable in UTexture Or GetRunningPlatformData functiopn and try to get pixels from there.

I have seen such example in PaperAtlasTextureHelpers.cpp:

bool FPaperAtlasTextureHelpers::ReadSpriteTexture(UTexture* SourceTexture, const FIntPoint& SourceXY, const FIntPoint& SourceSize, TArray<uint8>& TargetBuffer)
		const int32 BytesPerPixel = 4;
		TargetBuffer.AddZeroed(SourceSize.X * SourceSize.Y * BytesPerPixel);

	FTextureSource& SourceData = SourceTexture->Source;
	if (SourceData.GetFormat() == TSF_BGRA8)
		uint32 BytesPerPixel = SourceData.GetBytesPerPixel();
		uint8* OffsetSource = SourceData.LockMip(0) + (SourceXY.X + SourceXY.Y * SourceData.GetSizeX()) * BytesPerPixel;
		uint8* OffsetDest = TargetBuffer.GetData();
		CopyTextureData(OffsetSource, OffsetDest, SourceSize.X, SourceSize.Y, BytesPerPixel, SourceData.GetSizeX() * BytesPerPixel, SourceSize.X * BytesPerPixel);
		UE_LOG(LogPaper2DEditor, Error, TEXT("Sprite texture %s is not BGRA8, which isn't supported in atlases yet"), *SourceTexture->GetName());

	return true;