How to read landscape height map data from C++

I would like the read the height map data of the editor initialized landscape (in C++) so that I can pass the data to our server application which internally handles physics.

But I could not find a satisfactory method of doing it. And I have many questions.

I’ve retrieved the the only ALandscape instance (the landscape) in my scene and iterated over its ULanscapeComponents. At each landscape component there is the HeightMapTexture variable which supposedly holds the data.

I’ve adapted the following code from the Import method that resides inside LandscapeEdit.cpp…

Terrain * ConvertUnrealLandscapeToTerrain(ALandscape * landscape)
{ 
   ...
   ...

   TInlineComponentArray<ULandscapeComponent*> components;
   landscape->GetComponents<ULandscapeComponent>(components);
    
    for (auto i = components.CreateIterator(); i; i++) {
       UTexture2D * heightMapTexture = (*i)->HeightmapTexture;
       FColor* heightMapData = (FColor*)heightMapTexture->Source.LockMip(0);
    
       //TODO: Read the data from the array here and convert.
    
       heightMapTexture->Source.UnlockMip(0);
    }

   ...
   ...
}

landscape is the instance of the ALandscape actor class which I’ve retrieved from the scene. The problem here is that the heightMapData array entries does not make any sense when I check them in debug mode and Visual Studio shows some weird text characters in place of the RGBA channels of the FColors.

How does Unreal store height map of a landscape internally? Is it an 16 bit greyscale image encoded in two channels (8 bits * 2). If that is so which channels.

How to decode and properly access this data in general?

Thanks in advance for answers.

I’ve answered my own question in another post: