# Landscape Heightmap in C++

**URL:** <https://forums.unrealengine.com/t/landscape-heightmap-in-c/421262>\
**Category:** World Creation\
**Tags:** landscapes, unreal-engine, api, heightmap, UE4, question\
**Created:** [March 29, 2018, 9:45pm UTC](https://forums.unrealengine.com/t/landscape-heightmap-in-c/421262 "2018-03-29T21:45:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![MowLiao](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MowLiao](https://forums.unrealengine.com/u/MowLiao)\
**Post date:** [March 29, 2018, 9:45pm UTC](https://forums.unrealengine.com/t/landscape-heightmap-in-c/421262/1 "2018-03-29T21:45:39Z")

</div>

I’m really new to programming in C++ in UE4, and all I want to do is bring in the landscape heightmap and read it programmatically to then place collision boxes on it at equal distances (in like a grid). Everything else I need to do at the moment can be done via the editor using blueprints etc.

So I’ve spent the last two days looking through the code, blowing my mind up with its complexity and lack of real documentation for landscapes. So far I have the following code to bring in the heightmap - just some slightly altered lines from the methods `SplitHeightMap()` in LandscapeEdMode.cpp and `ExportHeightmap()` in LandscapeEdit.cpp:

```
#include "LandscapeCollision.h"
#include "LandscapeEdit.h"
#include "LandscapeInfo.h"
#include "Landscape.h"
#include "EngineUtils.h"

void ALandscapeCollision::importHeightMap()
{
	int32 MinX = MAX_int32;
	int32 MinY = MAX_int32;
	int32 MaxX = -MAX_int32;
	int32 MaxY = -MAX_int32;
	UWorld* World = GetWorld();
	LANDSCAPE_API ULandscapeInfo* landscapeInfo;

	for (TActorIterator<ALandscape> ALandscapeItr(World); ALandscapeItr; ++ALandscapeItr)
	{
		landscapeInfo = ALandscapeItr->GetLandscapeInfo();

		FLandscapeEditDataInterface landscape(landscapeInfo);

		TArray<uint16> HeightData;
		HeightData.AddZeroed((MaxX - MinX + 1) * (MaxY - MinY + 1));
		landscape.GetHeightDataFast(MinX, MinY, MaxX, MaxY, HeightData.GetData(), 0);

		this->heightMap = HeightData;
	}

}

```

I’m really aware my code is far from perfect at this point.

Anyway, so far I think my main issue is correctly referencing to API\_LANDSCAPE in certain places. My Build.cs file has:

```
		PublicDependencyModuleNames.AddRange(new string[] {
            "Core",
            "CoreUObject",
            "Engine",
            "InputCore" });

		PrivateDependencyModuleNames.AddRange(new string[] {
            "Landscape" });

```

And the errors I’m coming into are along the lines of:

```
CompilerResultsLog: Error: LandscapeCollision.cpp.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) class ULandscapeInfo * landscapeInfo" (__imp_?landscapeInfo@@3PEAVULandscapeInfo@@EA)

```

and depending on if I place `LANDSCAPE_API` on various lines:

```
CompilerResultsLog: Error C2491: 'landscape': definition of dllimport data not allowed
CompilerResultsLog: Error C2205: 'landscape': cannot initialize extern variables with block scope

```

Can anyone give me any insight into what I can do to get this code to work? Thanks so much.

---

<div class="post-metadata">

**Author:** ![hellobomm](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/hellobomm/32/552631_2.png) [@hellobomm](https://forums.unrealengine.com/u/hellobomm)\
**Post date:** [October 19, 2020, 3:11pm UTC](https://forums.unrealengine.com/t/landscape-heightmap-in-c/421262/2 "2020-10-19T15:11:29Z")

</div>

Hello MowLiao, did you figure this out? I am also stuck at the same problem

---

<div class="post-metadata">

**Author:** ![MowLiao](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@MowLiao](https://forums.unrealengine.com/u/MowLiao)\
**Post date:** [October 20, 2020, 1:39pm UTC](https://forums.unrealengine.com/t/landscape-heightmap-in-c/421262/3 "2020-10-20T13:39:30Z")

</div>

Sadly not. I abandoned this attempt shortly after seeing no replies because I had a tight deadline, and this was for a side project. Good luck with your implementation!

---

<div class="post-metadata">

**Author:** ![hellobomm](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/hellobomm/32/552631_2.png) [@hellobomm](https://forums.unrealengine.com/u/hellobomm)\
**Post date:** [October 26, 2020, 4:57pm UTC](https://forums.unrealengine.com/t/landscape-heightmap-in-c/421262/4 "2020-10-26T16:57:52Z")

</div>

thank you!!!
