# I Stuck in creating a landscape heightmap Import macro. Plz Help. C++ Editor Scripting.

**URL:** <https://forums.unrealengine.com/t/i-stuck-in-creating-a-landscape-heightmap-import-macro-plz-help-c-editor-scripting/1923073>\
**Category:** Editor Scripting\
**Tags:** unreal-engine, question\
**Created:** [July 1, 2024, 6:19pm UTC](https://forums.unrealengine.com/t/i-stuck-in-creating-a-landscape-heightmap-import-macro-plz-help-c-editor-scripting/1923073 "2024-07-01T18:19:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aspartemeart](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@Aspartemeart](https://forums.unrealengine.com/u/Aspartemeart)\
**Post date:** [July 1, 2024, 6:19pm UTC](https://forums.unrealengine.com/t/i-stuck-in-creating-a-landscape-heightmap-import-macro-plz-help-c-editor-scripting/1923073/1 "2024-07-01T18:19:04Z")

</div>

Hey everyone,  
I am trying to import a Heightmap and Weightmaps to Update Landscape with Unreal Editor script.  
Cuz I reimport those maps a lot, And I’d like to skip the step of setting filepath to Landscap ImportUI every time. So, I Looked up “LandscapeEditor/Private/LandscapeEdMode.cpp” And try to work my code. It’s not Realtime. I just need run it for Editor.

Well, My problem is I Read HeightData from the file right, and I set HeightData with “FHeightmapAccessor” to the Landscap, But nothing had changed. There is no Error, And even LandscapeStremingProxies actors are get modify marks as well. but no changed. I think I skipped some important step that necessary.

Someone Plz tell me what I’m missing.  
I Put my Code I’m working on Blow.  
Thanks.

void UMyUnrealPlugInsBPLibrary::ImportLandscapeHeightmap(ALandscape\* Landscape, FString Path)  
{

```
auto ActualPath = Path.IsEmpty() ? Landscape->ReimportHeightmapFilePath : Path;
ULandscapeInfo* LandscapeInfo = Landscape->GetLandscapeInfo();
auto LandscapeSize = Landscape->GetLoadedBounds();	
int32 NumSamplesX = (LandscapeSize.GetSize().X * 0.01) + 1;
int32 NumSamplesY = (LandscapeSize.GetSize().Y * 0.01) + 1;

TArray<uint16> HeightData;
ReadHeightmapFile(HeightData, *ActualPath, NumSamplesX, NumSamplesY);
if (NumSamplesX * NumSamplesY != HeightData.Num())
{
	UE_LOG(LogTemp, Warning, TEXT("Invalid Heightmap data."));
}else
{
	UE_LOG(LogTemp, Warning, TEXT("Import %s Heightmap Data Loaded."), *ActualPath);
}

int32 MinX, MinY, MaxX, MaxY;
LandscapeInfo->GetLandscapeExtent(MinX, MinY, MaxX, MaxY);

Landscape->RequestLayersContentUpdate(ELandscapeLayerUpdateMode::Update_Heightmap_All);
FHeightmapAccessor<false> HeightmapAccessor(LandscapeInfo);
HeightmapAccessor.SetData(MinX, MinY, MaxX, MaxY, (uint16*)HeightData.GetData());
Landscape->PostEditChange();
return;

```

}

bool UMyUnrealPlugInsBPLibrary::ReadHeightmapFile(TArray& Result, const FString& Filename, int32 ExpectedWidth, int32 ExpectedHeight)  
{

```
bool bResult = true;
ILandscapeEditorModule& LandscapeEditorModule = FModuleManager::GetModuleChecked<ILandscapeEditorModule>("LandscapeEditor");
const ILandscapeHeightmapFileFormat* HeightmapFormat = LandscapeEditorModule.GetHeightmapFormatByExtension(*FPaths::GetExtension(Filename, true));
FLandscapeHeightmapImportData ImportData = HeightmapFormat->Import(*Filename, { (uint32)ExpectedWidth, (uint32)ExpectedHeight });
if (ImportData.ResultCode != ELandscapeImportResult::Error)
{
	Result = MoveTemp(ImportData.Data);
}
else
{
	UE_LOG(LogStreaming, Warning, TEXT("%s"), *ImportData.ErrorMessage.ToString());
	Result.Empty();
	bResult = false;
}
return bResult;

```

}
