C++ Problem reading UTexture2D data

I have a texture where the format is R32F and I want to read the data. For simplicity of not having to deal with threads I’m just trying to get it in one go in the game thread, it’s also just an editor only thing.

The problem with the code below is the mip data doesn’t exist in mip 0 but in a 32x32 mip so it throws an error. Not sure what to do. Steaming is disabled on the texture.

UTexture2D* SourceTexture = Texture.LoadSynchronous();
SourceTexture->SetForceMipLevelsToBeResident(30.0f);

#if WITH_EDITOR
if (SourceTexture && SourceTexture->IsCompiling())
{
    FTextureCompilingManager::Get().FinishCompilation({ SourceTexture });
}
#endif

const FIntPoint Resolution = FIntPoint(SourceTexture->GetSizeX(), SourceTexture->GetSizeY());
OutData.SetNumUninitialized(Resolution.X * Resolution.Y);

const int32 TotalBytes = Resolution.X * Resolution.Y * sizeof(float);

FTexturePlatformData* PlatformData = SourceTexture->GetPlatformData();
FTexture2DMipMap& Mip = PlatformData->Mips[0];
float* Data = static_cast<float*>(Mip.BulkData.Lock(LOCK_READ_ONLY));
FMemory::Memcpy(OutData.GetData(), Data, TotalBytes);
Mip.BulkData.Unlock();

Managed to get a solution. I’m on 5.7 so I’m not sure how far back this will go but the following works for me.

UTexture2D* SourceTexture = Texture.LoadSynchronous();
SourceTexture->SetForceMipLevelsToBeResident(30.0f);

#if WITH_EDITOR
if (SourceTexture && SourceTexture->IsCompiling())
{
    FTextureCompilingManager::Get().FinishCompilation({ SourceTexture });
}
#endif

FImage OutImage;
FImageUtils::GetTexture2DSourceImage(SourceTexture, OutImage)
		
const TArrayView64<float> Data = OutImage.AsR32F();
		
const FIntPoint Resolution = FIntPoint(SourceTexture->GetSizeX(), SourceTexture->GetSizeY());
OutDistanceFieldData.SetNumUninitialized(Resolution.X * Resolution.Y);
		
const int32 TotalBytes = Resolution.X * Resolution.Y * sizeof(float);
		
FMemory::Memcpy(OutData.GetData(), Data.GetData(), TotalBytes);