Getting random color pixels from Texture2D

I have been trying to get the RGB values of a specific pixel in my texture2D, unfortunately I keeps giving me different values for the same pixel which leads me to believe I did something wrong. I don’t think my pixel rgb should change since it’s the same texture every time, although every time I run my program I reimport the image, but I don’t think that should have an effect because its the exact same image. I change the settings of my Texture2D before I start to find the pixel information but it still returns random colors

FColor UMyFileImporter::GetPixelData(UTexture2D* Texture, int32 X, int32 Y)
	{
		Texture->MipGenSettings.operator=(TMGS_NoMipmaps);
		Texture->SRGB = false;
		Texture->CompressionSettings.operator=(TC_VectorDisplacementmap);
		FTexture2DMipMap* MyMipMap = &Texture->PlatformData->Mips[0];
		FByteBulkData* RawImageData = &MyMipMap->BulkData;
		FColor* FormatedImageData = static_cast<FColor*>(RawImageData->Lock(LOCK_READ_ONLY));
		uint8 PixelX = X, PixelY = Y;
		uint32 TextureWidth = MyMipMap->SizeX, TextureHeight = MyMipMap->SizeY;
		FColor PixelColor;
		if (PixelX >= 0 && PixelX < TextureWidth && PixelY >= 0 && PixelY < TextureHeight)
		{
			PixelColor = FormatedImageData[PixelY * TextureWidth + PixelX];
		}
		RawImageData->Unlock();
		return PixelColor;
	}

My method works. There was something wrong with the Texture I was getting.

Hey, I did the same thing as you did, exactly the same, but my editor keeps crashing. Any idea why that might be happening? could you tell me how did you call this function, and what are your image import settings?

How did you get on with this?

I’m having a crash at the moment because FormattedImageData is coming up as a nullptr. I believe (still testing) that this is because the larger mipmaps hadn’t been loaded. I’m now going through the mipmaps one at a time to find one where BulkData->BulkData is not nullptr and using that one.