Procedural Landscape Generation from Data (BP, C++)

Hey folks, we want to create procedural landscapes from freely available geological and height data. We’ve been following the book “Unreal Engine 4 Scripting with C++ Cookbook”, which is a little older. The code adapted accordingly also works well, until it comes to updating the landscape. It crashes at:


int32 numHeights = (rect.Width()+1)*(rect.Height()+1);
TArray<uint16> Data;
Data.Init( 0, numHeights );
for( int i = 0; i < Data.Num(); i++ ) {
float nx = (i % cols) / cols; // normalized x value
float ny = (i / cols) / rows; // normalized y value
Data* = GeoHeightData( nx, ny, 16, 4, 4 );
}
LandscapeEditorUtils::SetHeightmapData( landscape, Data );

The function


LandscapeEditorUtils::SetHeightmapData( landscape, Data );

no longer exists. In LandscapeEdit.h you can find the


LandscapeEdit::SetHeightData

. This is defined by


SetHeightData(InMinX, InMinY, InMaxX, InMaxY, (uint16*)ImportHeightData->GetData(), 0, false, nullptr);

is this function the equivalent to SetHeightmapData? The engine crushes with this approach too.

Do you have any suggestions or workarounds for creating procedural landscapes, either from blueprint or code? We also checked out the approach of Christian Sparks (https://hippowombat.tumblr.com/post/…-ue4-420#notes), which is cool, but we need the landscape for runtime applications.
Thx!

You use a gray scale image right ? also known as a height map.
I’m also intrested in loading height maps and converting them to land.

If you crash you must get an error, the crash opens an error, what does it say there ?
You also have to have the error from the module it is causing it with the file and line that is causing the error

Then the line error from your local project file cpp, as you said it crashes at (What line ?)
That is not defined by you, you gave a bunch of lines.
What is the line that it is causing it, can you copy paste just the line that is causing the error.

Is it this ?
LandscapeEditorUtils::SetHeightmapData( landscape, Data );

You also need the error from the module file with the line where the error is in the module.
It’s in the error window when it pops up after it crashes.
Maybe we can get it to work because I want something like this too.

You should also pay atention to unreal’s recomandations regarding height maps, maybe why it crashes on you. It has to be 8 bits has to have a resolution maximum of something X something.

Says here.
Creating and Using Custom Heightmaps and Layers | Unreal Engine Documentation
Images for the built-in formats are still required to be grayscale, 8 bits per pixel, single channel files in either .PNG or .RAW format.

Maybe they use similar functions to import to unreal with the editor and you are using a function that has to have some image format validity maybe meaning the image has to have these values otherwise it will crash. Just check this first.