I’m trying to access the bulkdata in the heightmap of a landscape component, but trying to lock() the data always returns a null pointer.
I’ve checked and the bulkdata is available and unlocked, so I can’t seem to figure out why its not returning anything
Here’s my code:
for (auto& LandscapeComponent : Landscape->LandscapeComponents)
{
if (LandscapeComponent->HeightmapTexture)
{
FTexturePlatformData& PlatformData = *LandscapeComponent->HeightmapTexture->PlatformData;
if (PlatformData.Mips.Num())
{
FTexture2DMipMap& MyMipMap = PlatformData.Mips[0];
FColor* FormatedImageData = (FColor*)(MyMipMap.BulkData.Lock(LOCK_READ_ONLY));
if (FormatedImageData)
{
for (int32 X = 0; X < LandscapeComponent->HeightmapTexture->GetSizeX(); X++)
{
for (int32 Y = 0; Y < LandscapeComponent->HeightmapTexture->GetSizeY(); Y++)
{
NewLandscapeHeightmap.GetRawXY(LandscapeComponent->SectionBaseX + X, LandscapeComponent->SectionBaseY + Y) = FormatedImageData[X + (Y * LandscapeComponent->HeightmapTexture->GetSizeX())].R;
}
}
}
else
{
GEngine->AddOnScreenDebugMessage(INDEX_NONE, 10.f, FColor::Red, FString("Unable to lock the platform data"));
}
MyMipMap.BulkData.Unlock();
}
}
}
It always prints out “Unable to lock the platform data”