Download

Get Interp'd Landscape Z from XY in World-Space from Heightmap

I humbly request a universal static function that allows a user to get the interpolated altitude (Z) value in World-Space XY on a landscape from the height map data.

The only way to do this at the moment is by line-tracing from somewhere in orbit down to the ground to find the position in world space, which is incredibly inefficient since the heightmap data is already there. Myself and others have hunted through the API but it doesn’t seem easy to actually get to the height information in the landscape.

I haven’t tried this but isn’t it already possible to read the pixels from the heightmap texture in C++? You would only need to read 1 pixel at the given x/y coordinate and then do a tiny bit of math (it might end up more expensive than tracing though).

Again, I never tried any of this… just food for thought :slight_smile:

That is genius! But you are right - there might be some performance implications. If a level map is really big then reading a file with the height map could take a lot of time. And I am not talking about math you mentioned.

That’s pretty much exactly what I’m trying to do, but it doesn’t seem like it’s actually possible to get to that height information at runtime.

The issue with the Heightmap approach is that Landscapes might be rotated, scaled, have chunks missing etc - or there could be multiple ones. I want to treat them all as though they are the same. I think the trace-from-heaven route is my only option at the moment, but that’s going to add a lot of loading time :confused:

you can get a ULandscapeInfo* from a ALandscape* then you can create a FLandscapeEditDataInterface and then use its GetHeightDataFast function to fill a TArray<uint16> Data.

Thanks Chooka, that’s a good start but unfortunately that class is Editor only so it won’t work in a standalone game. Also at the bottom-end it only seems to return the original height map data by the looks of it, so precision will probably be low and not world-based.