I am using unreal engine 5.5 and trying to generate landscape using import API, I saw one example here but every time it is crashing with this error (Assertion failed: Pair != nullptr [File:D:\build++UE5\Sync\Engine\Source\Runtime\Core\Public\Containers\Map.h] [Line: 690] ). can any one help me here. Not sure if there is bug in this version or there is missing part, it seems all correct, for the simplicity I place all hardcoded values.
void ATestActor::CreateLandscape()
{
// ── HARD-CODED TEST PARAMETERS ───────────────────
const int32 SectionSize = 63; // quads per subsection
const int32 NumSubsections = 1; // subsections per component
const int32 ComponentCountX = 1; // how many components in X
const int32 ComponentCountY = 1; // how many components in Y
const int32 QuadsPerComponent = SectionSize * NumSubsections; // 63
const int32 W = ComponentCountX * QuadsPerComponent + 1; // 64 samples
const int32 H = ComponentCountY * QuadsPerComponent + 1; // 64 samples
// ── BUILD A FLAT HEIGHT FIELD AT MID-GREY ───────
TArray<uint16> RawHeights;
RawHeights.Init(32768, W * H);
// ── SPAWN THE LANDSCAPE ──────────────────────────
FActorSpawnParameters P;
P.SpawnCollisionHandlingOverride =
ESpawnActorCollisionHandlingMethod::AlwaysSpawn;
ALandscape* Landscape = GetWorld()->SpawnActor<ALandscape>(
ALandscape::StaticClass(),
FTransform(FVector::ZeroVector), // we ignore Bounds here
P
);
if (!Landscape)
{
UE_LOG(LogTemp, Error, TEXT("🔴 Failed to spawn ALandscape"));
return;
}
// ── CONFIGURE IMPORT GUID & SIZES ────────────────
const FGuid ImportGuid = FGuid::NewGuid(); // default‐constructed zero GUID
Landscape->SetLandscapeGuid(ImportGuid);
Landscape->LandscapeMaterial = nullptr;
Landscape->SubsectionSizeQuads = SectionSize;
Landscape->NumSubsections = NumSubsections;
Landscape->ComponentSizeQuads = QuadsPerComponent;
Landscape->CreateLandscapeInfo(true, true);
// ── PACKAGE HEIGHT + (EMPTY) MATERIAL LAYERS ────
TMap<FGuid, TArray<uint16>> HeightDataPerLayer;
HeightDataPerLayer.Add(ImportGuid, MoveTemp(RawHeights));
TMap<FGuid, TArray<FLandscapeImportLayerInfo>> MaterialLayerInfos;
// empty array here — ensures .Num()==1 just like HeightDataPerLayer
MaterialLayerInfos.Add(ImportGuid, TArray<FLandscapeImportLayerInfo>());
// ── CALL THE POINTER OVERLOAD (11 PARAMS) ────────
Landscape->Import(
/*InGuid*/ ImportGuid,
/*InMinX*/ 0,
/*InMinY*/ 0,
/*InMaxX*/ W - 1,
/*InMaxY*/ H - 1,
/*InNumSubsections*/ NumSubsections,
/*InSubsectionSizeQuads*/ SectionSize,
/*InImportHeightData*/ HeightDataPerLayer,
/*InHeightmapFileName*/ TEXT(""), // no source file
/*InImportMaterialLayerInfos*/ MaterialLayerInfos,
/*InImportMaterialLayerType*/ ELandscapeImportAlphamapType::Additive
// InImportLayers defaults to nullptr
);
// ── FINALIZE & SELECT ────────────────────────────
Landscape->PostEditChange();
Landscape->RegisterAllComponents();
#if WITH_EDITOR
GEditor->SelectNone(false, true);
GEditor->SelectActor(Landscape, true, true);
#endif
UE_LOG(LogTemp, Log, TEXT("✅ Hard-coded landscape imported (%d×%d)"), W, H);
}