# How to load heighmap in C++

**URL:** <https://forums.unrealengine.com/t/how-to-load-heighmap-in-c/408399>\
**Category:** World Creation\
**Tags:** unreal-engine, Landscape, heightmap, CPP, question\
**Created:** [October 31, 2017, 1:24pm UTC](https://forums.unrealengine.com/t/how-to-load-heighmap-in-c/408399 "2017-10-31T13:24:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_c12ce391](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_c12ce391](https://forums.unrealengine.com/u/anonymous_user_c12ce391)\
**Post date:** [October 31, 2017, 1:24pm UTC](https://forums.unrealengine.com/t/how-to-load-heighmap-in-c/408399/1 "2017-10-31T13:24:56Z")

</div>

Hi,

I am trying to make same world generation. I want to load few heightmaps from files and load them to landscapes. Same thing you can do in GUI. Where should I load read data? I have found in ULandscapeComponent function InitHeightmapData() ← if I will load map by this it will work? There is also ReimportHeightmapFilePath in ALandscape, but what is it at all? How to “refresh” this heighmap?

I will be very grateful for any ideas 🙂

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_c12ce391](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_c12ce391](https://forums.unrealengine.com/u/anonymous_user_c12ce391)\
**Post date:** [May 11, 2018, 12:47pm UTC](https://forums.unrealengine.com/t/how-to-load-heighmap-in-c/408399/2 "2018-05-11T12:47:04Z")

</div>

My only solution now is to create ProceduralMesh from heightmap file by myself. It doesn’t have any functionality from Landscape, by visually works.

---

<div class="post-metadata">

**Author:** ![avol](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@avol](https://forums.unrealengine.com/u/avol)\
**Post date:** [November 23, 2023, 6:51am UTC](https://forums.unrealengine.com/t/how-to-load-heighmap-in-c/408399/3 "2023-11-23T06:51:30Z")

</div>

Since nobody ever helps here with this question, I’l do. I managed to make procedural landscape in multiple ways (albeit took me a month of looking throuhg plugins, experimenting, even trying to make my own landscape solution)  
.

1. load from texture using: LandscapeTest-\>LandscapeComponents[i]-\>SetHeightmap(HeightMap);

2. load from rendertexture using:  
||TArray SurfData;|  
|—|—|  
||auto RenderTarget = RTHeightMap-\>GameThread\_GetRenderTargetResource();|  
||RenderTarget-\>ReadPixels(SurfData);|

3. just writing heights to FColor:

Additionally need to call some function to trigger the redraw and recreate collisions:

```
for (int i = 0; i < LandscapeTest->LandscapeComponents.Num(); i++)
{
	LandscapeTest->LandscapeComponents[i]->MarkRenderStateDirty();

	LandscapeTest->LandscapeComponents[i]->InitHeightmapData(SurfData, true);

	// NOTE: crash if edit layers is on.
	// NOTE: crash cuz of no mips.
	// NOTE: srgb collision offset?
	//LandscapeTest->LandscapeComponents[i]->SetHeightmap(HeightMap);
	LandscapeTest->LandscapeComponents[i]->RequestHeightmapUpdate(true, true);

	LandscapeTest->LandscapeComponents[i]->UpdateCachedBounds(true);
	LandscapeTest->LandscapeComponents[i]->PostLoad();
}

//for (int i = 0; i < LandscapeTest->CollisionComponents.Num(); i++)
//	LandscapeTest->CollisionComponents[i]->RecreateCollision();

LandscapeTest->RecreateCollisionComponents();

```
