Hello I want create landscape in editor, and attach Landscape Material, Landscape Hole material and weight data.
I stuck at spawning blank landscape, here’s my code:
int width = 1024;
int height = 1024;
int quads_per_section = 63;
int number_of_sections = 1;
int components_x = 8;
int components_y = 8;
int new_width = quads_per_section * number_of_sections * components_x + 1;
int new_height = quads_per_section * number_of_sections * components_y + 1;
int offset_x = (new_width - width) / 2;
int offset_y = (new_height - height) / 2;
TArray<uint16> original_data;
for (int w = 0; w < width; w++) {
for (int h = 0; h < height; h++) {
original_data.Add(32767);
}
}
TArray<uint16> data = LandscapeEditorUtils::ExpandData<uint16>(original_data, 0, 0, width - 1, height - 1, -offset_x, -offset_y, new_width - offset_x - 1, new_height - offset_y - 1);
ALandscapeProxy *landscape = nullptr;
FVector location = FVector(0, 0, 0);
FRotator rotation = FRotator(0, 0, 0);
landscape = (ALandscapeProxy*)(GEngine->GetWorld()->SpawnActor(ALandscape::StaticClass(), &location, &rotation));
int layer_type = (int)ELandscapeImportAlphamapType::Additive;
int quads_per_component = number_of_sections * quads_per_section;
int size_x = components_x * quads_per_component + 1;
int size_y = components_y * quads_per_component + 1;
TArray<FLandscapeImportLayerInfo> infos;
TMap<FGuid, TArray<uint16>> HeightDataPerLayers;
HeightDataPerLayers.Add(FGuid(), data);
TMap<FGuid, TArray<FLandscapeImportLayerInfo>> MaterialLayersInfo;
MaterialLayersInfo.Add(FGuid(), infos);
landscape->Import(FGuid::NewGuid(), 0, 0, size_x - 1, size_y - 1, number_of_sections, quads_per_section, HeightDataPerLayers, nullptr, MaterialLayersInfo, (ELandscapeImportAlphamapType)layer_type);
landscape->SetActorScale3D(FVector(50,50,50));
Editor crash at line: ** landscape = (ALandscapeProxy*)(GEngine->GetWorld()->SpawnActor(ALandscape::StaticClass(), &location, &rotation));
How to properly initialize new landscape in editor in C++ plugin ?