Landscape from heightmap - Problem with file format

So basically, to get a good looking height map you need the file to be in a linear color space.

The problem is that Unreal only accepts PNG and RAW files. PNG doesn’t support linear color space, and Blender doesn’t export RAW files.

Soo how can I export a height map that’ll look correctly? And why doesn’t unreal accept EXR image files for generating the landscapes?

Unreal Landscape importer treats a PNG 16-bit grayscale image as a linear numeric range, where 0 is the lowest altitude, 65535 is the highest altitude, and 32767 is the center.
As far as I know from testing, it is a “profile unaware” import, and not sGRAY or Dot Gain 20% etc. And most software that creates heightmaps do not use profiles, so that does not mean “assume sRGB or sGRAY”, it means no profile.
The grayscale numerical value for the Landscape mesh is simply determined directly as 65536 / 512 unreal units along the Z axis and assigned to a mesh vertex elevation.
So Scale Z of 100 is 512 meters of unreal engine elevation range, with the PNG values being linearly divided within that as floating-point values.
I convert Digital Elevation Model files that are floating-point real elevations in meters to a standard PNG-16 using direct floating-point to integer numeric conversion, and the resulting elevations in Unreal are always correct, and that is with a “profile unaware” PNG-16 file.
AFAIK the PNG Encoder/Decoder does not use ICC or Gamma chunks, so the data as managed by the Landscape importer is treated as linear.
So if Blender is adding an sRGB ICCP chunk, and that is messing up your heightmap elevations, you will have to use other software, unless you can stop Blender from embedding and using sRGB/sGRAY in PNG images and modifying the values when exporting.
Blender shouldn’t be modifying the raw values anyway, any profile is used only for how it is displayed.
As to why Unreal doesn’t support EXR you will have to ask Epic.

I had a look at the Blender documentation.
Blender works in linear space.
If you want to save an image as linear, set it to “non-color”.
This is used for bump maps and other images that are treated as linear numbers, including AO, Rough, Specular, etc.
Blender’s PNG format writing has to support linear space otherwise these textures wouldn’t work in UE or other apps, they would be gamma’ed.
And PNG can contain linear data, if a color profile iCC chunk or a gAMA chunk is written to the file, the PNG encoder doesn’t modify the data stream, it will stay as whatever data was written by the software, including linear numbers.
I do this in my software using the industry standard libpng, so I know that PNG can contain linear numeric values.