I create landscape in C++, it successfully generates the landscape I want, but the landscape not behaves like the one generated in editor landscape mode. Here is a picture, in which yellow line shows the landscape generated in editor, white line shows the landscape generated in c++. The former have LODs and regions, the latter doesn’t. I have checked FLandscapeEditorDetailCustomization_NewLandscape::OnCreateButtonClicked. Basically the only different thing UE5 source code dose is divide the landscape into a lot of regions. So, is that the problem? And how should I do to add LODs to my created Landscape?
Here is my code:
TMap<FGuid, TArray<uint16>> HeightDataPerLayers;
HeightDataPerLayers.Add(FGuid(),MoveTemp(HeightData));
TArray<FLandscapeImportLayerInfo> MaterialImportLayers;
MaterialImportLayers.Reserve(0);
TMap<FGuid,TArray<FLandscapeImportLayerInfo>> MaterialLayerDataPerLayers;
MaterialLayerDataPerLayers.Add(FGuid(), MoveTemp(MaterialImportLayers));
UWorld* CurrentWorld = GetWorld();
FTransform LandscapeTransform = FTransform::Identity;
LandscapeTransform.SetScale3D(UE::Math::TVector<double>(100,100,100));
LandscapeTransform.SetLocation(UE::Math::TVector<double>(0,0,0));
ALandscape* Landscape = CurrentWorld->SpawnActor<ALandscape>();
Landscape->bCanHaveLayersContent = false;
Landscape->LandscapeMaterial = Material;
Landscape->SetActorTransform(LandscapeTransform);
Landscape->StaticLightingLOD = FMath::DivideAndRoundUp(FMath::CeilLogTwo((LandscapeSize * LandscapeSize) / (2048 * 2048) + 1), (uint32)2);
Landscape->Import(FGuid::NewGuid(),0,0,LandscapeSize-1,LandscapeSize-1,SectionsPerComponent,QuadsPerSection,
HeightDataPerLayers, nullptr, MaterialLayerDataPerLayers, ELandscapeImportAlphamapType::Additive);
UDatasmithLandscapeTemplate* LandscapeTemplate = NewObject< UDatasmithLandscapeTemplate >( Landscape->GetRootComponent() );
LandscapeTemplate->StaticLightingLOD = FMath::DivideAndRoundUp(FMath::CeilLogTwo((LandscapeSize * LandscapeSize) / (2048 * 2048) + 1), (uint32)2);
LandscapeTemplate->Apply( Landscape );
ULandscapeInfo* LandscapeInfo = Landscape->GetLandscapeInfo();
LandscapeInfo->UpdateLayerInfoMap(Landscape);
Landscape->RegisterAllComponents();
FPropertyChangedEvent MaterialPropertyChangedEvent(FindFieldChecked< FProperty >(Landscape->GetClass(), FName("LandscapeMaterial")));
Landscape->PostEditChangeProperty(MaterialPropertyChangedEvent);
Landscape->PostEditChange();