I wrote a C++ code to generate a landscape and compiled it, but I got the error below.
(using the GeneratehHeightmapMips and GenerateWeightmapMips and UpdateCollisionHeightData functions)
Error: GenerateHeightmapMips(maybe) ↓
GenerateLandscape.cpp.obj : error LNK2019: unresolved external symbol "public: void __cdecl ULandscapeComponent::GenerateHeightmapMips(class TArray<struct FColor *,class TSizedDefaultAllocator<32> > &,int,int,int,int,struct FLandscapeTextureDataInfo *)" (?GenerateHeightmapMips@ULandscapeComponent@@QEAAXAEAV?$TArray@PEAUFColor@@V?$TSizedDefaultAllocator@$0CA@@@@@HHHHPEAUFLandscapeTextureDataInfo@@@Z) referenced in function "public: void __cdecl UGenerateLandscape::Import(struct FGuid const &,int,int,int,int,int,int,class TMap<struct FGuid,class TArray<unsigned short,class TSizedDefaultAllocator<32> >,class FDefaultSetAllocator,struct TDefaultMapHashableKeyFuncs<struct FGuid,class TArray<unsigned short,class TSizedDefaultAllocator<32> >,0> > const &,wchar_t const * const,class TMap<struct FGuid,class TArray<struct FLandscapeImportLayerInfo,class TSizedDefaultAllocator<32> >,class FDefaultSetAllocator,struct TDefaultMapHashableKeyFuncs<struct FGuid,class TArray<struct FLandscapeImportLayerInfo,class TSizedDefaultAllocator<32> >,0> > const &,enum ELandscapeImportAlphamapType,class TArray<struct FLandscapeLayer,class TSizedDefaultAllocator<32> > const *)" (?Import@UGenerateLandscape@@QEAAXAEBUFGuid@@HHHHHHAEBV?$TMap@UFGuid@@V?$TArray@GV?$TSizedDefaultAllocator@$0CA@@@@@VFDefaultSetAllocator@@U?$TDefaultMapHashableKeyFuncs@UFGuid@@V?$TArray@GV?$TSizedDefaultAllocator@$0CA@@@@@$0A@@@@@QEB_WAEBV?$TMap@UFGuid@@V?$TArray@UFLandscapeImportLayerInfo@@V?$TSizedDefaultAllocator@$0CA@@@@@VFDefaultSetAllocator@@U?$TDefaultMapHashableKeyFuncs@UFGuid@@V?$TArray@UFLandscapeImportLayerInfo@@V?$TSizedDefaultAllocator@$0CA@@@@@$0A@@@@@W4ELandscapeImportAlphamapType@@PEBV?$TArray@UFLandscapeLayer@@V?$TSizedDefaultAllocator@$0CA@@@@@@Z)
Error: GenerateWeightmapMips(maybe) ↓
GenerateLandscape.cpp.obj : error LNK2019: unresolved external symbol "public: static void __cdecl ULandscapeComponent::GenerateWeightmapMips(int,int,class UTexture2D *,struct FColor *)" (?GenerateWeightmapMips@ULandscapeComponent@@SAXHHPEAVUTexture2D@@PEAUFColor@@@Z) referenced in function "public: void __cdecl UGenerateLandscape::Import(struct FGuid const &,int,int,int,int,int,int,class TMap<struct FGuid,class TArray<unsigned short,class TSizedDefaultAllocator<32> >,class FDefaultSetAllocator,struct TDefaultMapHashableKeyFuncs<struct FGuid,class TArray<unsigned short,class TSizedDefaultAllocator<32> >,0> > const &,wchar_t const * const,class TMap<struct FGuid,class TArray<struct FLandscapeImportLayerInfo,class TSizedDefaultAllocator<32> >,class FDefaultSetAllocator,struct TDefaultMapHashableKeyFuncs<struct FGuid,class TArray<struct FLandscapeImportLayerInfo,class TSizedDefaultAllocator<32> >,0> > const &,enum ELandscapeImportAlphamapType,class TArray<struct FLandscapeLayer,class TSizedDefaultAllocator<32> > const *)" (?Import@UGenerateLandscape@@QEAAXAEBUFGuid@@HHHHHHAEBV?$TMap@UFGuid@@V?$TArray@GV?$TSizedDefaultAllocator@$0CA@@@@@VFDefaultSetAllocator@@U?$TDefaultMapHashableKeyFuncs@UFGuid@@V?$TArray@GV?$TSizedDefaultAllocator@$0CA@@@@@$0A@@@@@QEB_WAEBV?$TMap@UFGuid@@V?$TArray@UFLandscapeImportLayerInfo@@V?$TSizedDefaultAllocator@$0CA@@@@@VFDefaultSetAllocator@@U?$TDefaultMapHashableKeyFuncs@UFGuid@@V?$TArray@UFLandscapeImportLayerInfo@@V?$TSizedDefaultAllocator@$0CA@@@@@$0A@@@@@W4ELandscapeImportAlphamapType@@PEBV?$TArray@UFLandscapeLayer@@V?$TSizedDefaultAllocator@$0CA@@@@@@Z)
Error: UpdateCollisionHeightData(maybe) ↓
GenerateLandscape.cpp.obj : error LNK2019: unresolved external symbol "public: void __cdecl ULandscapeComponent::UpdateCollisionHeightData(struct FColor const *,struct FColor const *,int,int,int,int,bool,struct FColor const *,bool)" (?UpdateCollisionHeightData@ULandscapeComponent@@QEAAXPEBUFColor@@0HHHH_N01@Z) referenced in function "public: void __cdecl UGenerateLandscape::Import(struct FGuid const &,int,int,int,int,int,int,class TMap<struct FGuid,class TArray<unsigned short,class TSizedDefaultAllocator<32> >,class FDefaultSetAllocator,struct TDefaultMapHashableKeyFuncs<struct FGuid,class TArray<unsigned short,class TSizedDefaultAllocator<32> >,0> > const &,wchar_t const * const,class TMap<struct FGuid,class TArray<struct FLandscapeImportLayerInfo,class TSizedDefaultAllocator<32> >,class FDefaultSetAllocator,struct TDefaultMapHashableKeyFuncs<struct FGuid,class TArray<struct FLandscapeImportLayerInfo,class TSizedDefaultAllocator<32> >,0> > const &,enum ELandscapeImportAlphamapType,class TArray<struct FLandscapeLayer,class TSizedDefaultAllocator<32> > const *)" (?Import@UGenerateLandscape@@QEAAXAEBUFGuid@@HHHHHHAEBV?$TMap@UFGuid@@V?$TArray@GV?$TSizedDefaultAllocator@$0CA@@@@@VFDefaultSetAllocator@@U?$TDefaultMapHashableKeyFuncs@UFGuid@@V?$TArray@GV?$TSizedDefaultAllocator@$0CA@@@@@$0A@@@@@QEB_WAEBV?$TMap@UFGuid@@V?$TArray@UFLandscapeImportLayerInfo@@V?$TSizedDefaultAllocator@$0CA@@@@@VFDefaultSetAllocator@@U?$TDefaultMapHashableKeyFuncs@UFGuid@@V?$TArray@UFLandscapeImportLayerInfo@@V?$TSizedDefaultAllocator@$0CA@@@@@$0A@@@@@W4ELandscapeImportAlphamapType@@PEBV?$TArray@UFLandscapeLayer@@V?$TSizedDefaultAllocator@$0CA@@@@@@Z)
Finished Output:
C:\Users\User\Documents\Unreal Projects\Project\Binaries\Win64\UnrealEditor-Project.patch_0.exe : fatal error LNK1120: 3 unresolved externals
Failed to link patch (0.000s) (Exit code: 0x460)
.cpp file ↓
#include "GenerateLandscape.h"
#include "Landscape.h"
#include "LandscapeDataAccess.h"
#include "LandscapeEdit.h"
#include "LandscapeComponent.h"
#include "LandscapeProxy.h"
struct FWeightmapTextureAllocation
{
int32 X;
int32 Y;
int32 ChannelsInUse;
UTexture2D* Texture;
FColor* TextureData;
FWeightmapTextureAllocation(int32 InX, int32 InY, int32 InChannels, UTexture2D* InTexture, FColor* InTextureData)
: X(InX)
, Y(InY)
, ChannelsInUse(InChannels)
, Texture(InTexture)
, TextureData(InTextureData)
{}
};
struct FHeightmapInfo
{
int32 HeightmapSizeU;
int32 HeightmapSizeV;
UTexture2D* HeightmapTexture;
TArray<FColor*> HeightmapTextureMipData;
};
void UGenerateLandscape::Import(const FGuid& InGuid, int32 InMinX, int32 InMinY, int32 InMaxX, int32 InMaxY, int32 InNumSubsections, int32 InSubsectionSizeQuads, const TMap<FGuid, TArray<uint16>>& InImportHeightData,
const TCHAR* const InHeightmapFileName, const TMap<FGuid, TArray<FLandscapeImportLayerInfo>>& InImportMaterialLayerInfos, ELandscapeImportAlphamapType InImportMaterialLayerType, const TArray<FLandscapeLayer>* InImportLayers)
{
int32 dComponentSizeQuads;
const int32 VertsX = InMaxX - InMinX + 1;
const int32 VertsY = InMaxY - InMinY + 1;
dComponentSizeQuads = InNumSubsections * InSubsectionSizeQuads;
const int32 NumPatchesX = (VertsX - 1);
const int32 NumPatchesY = (VertsY - 1);
const int32 NumComponentsX = NumPatchesX / dComponentSizeQuads;
const int32 NumComponentsY = NumPatchesY / dComponentSizeQuads;
const int32 ComponentSizeVerts = dNumSubsections * (dSubsectionSizeQuads + 1);
const int32 ComponentsPerHeightmap = FMath::Min(MAX_HEIGHTMAP_TEXTURE_SIZE / ComponentSizeVerts, 1 << (UTexture2D::GetStaticMinTextureResidentMipCount() - 2));
// Remember where we have spare texture channels.
TArray<FWeightmapTextureAllocation> TextureAllocations;
for (int32 AllocationIndex = 0; AllocationIndex < TextureAllocations.Num(); AllocationIndex++)
{
UTexture2D* const WeightmapTexture = TextureAllocations[AllocationIndex].Texture;
FColor* const BaseMipData = TextureAllocations[AllocationIndex].TextureData;
// Generate mips for weightmaps
ULandscapeComponent::GenerateWeightmapMips(dNumSubsections, dSubsectionSizeQuads, WeightmapTexture, BaseMipData);
WeightmapTexture->Source.UnlockMip(0);
WeightmapTexture->BeginCachePlatformData();
WeightmapTexture->ClearAllCachedCookedPlatformData();
PendingTexturePlatformDataCreation.Add(WeightmapTexture);
}
// Generate mipmaps for the components, and create the collision components
for (int32 ComponentY = 0; ComponentY < NumComponentsY; ComponentY++)
{
for (int32 ComponentX = 0; ComponentX < NumComponentsX; ComponentX++)
{
const int32 HmX = ComponentX / ComponentsPerHeightmap;
const int32 HmY = ComponentY / ComponentsPerHeightmap;
FHeightmapInfo& HeightmapInfo = HeightmapInfos[HmX + HmY * NumHeightmapsX];
ULandscapeComponent* LandscapeComponent = proxy->LandscapeComponents[ComponentX + ComponentY * NumComponentsX];
LandscapeComponent->GenerateHeightmapMips(HeightmapInfo.HeightmapTextureMipData, ComponentX == NumComponentsX - 1 ? MAX_int32 : 0, ComponentY == NumComponentsY - 1 ? MAX_int32 : 0);
LandscapeComponent->UpdateCollisionHeightData(
HeightmapInfo.HeightmapTextureMipData[LandscapeComponent->CollisionMipLevel],
LandscapeComponent->SimpleCollisionMipLevel > LandscapeComponent->CollisionMipLevel ? HeightmapInfo.HeightmapTextureMipData[LandscapeComponent->SimpleCollisionMipLevel] : nullptr);
LandscapeComponent->UpdateCollisionLayerData();
}
}
}
.h file ↓
#pragma once
#include "CoreMinimal.h"
#include "UObject/ObjectMacros.h"
#include "Landscape.h"
#include "LandscapeComponent.h"
#include "Kismet/BlueprintFunctionLibrary.h"
#include "GenerateLandscape.generated.h"
/**
*
*/
UCLASS()
class PROJECT_API UGenerateLandscape : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
public:
void Import(const FGuid& InGuid, int32 InMinX, int32 InMinY, int32 InMaxX, int32 InMaxY, int32 InNumSubsections, int32 InSubsectionSizeQuads,
const TMap<FGuid, TArray<uint16>>& InImportHeightData, const TCHAR* const InHeightmapFileName, const TMap<FGuid, TArray<FLandscapeImportLayerInfo>>& InImportMaterialLayerInfos,
ELandscapeImportAlphamapType InImportMaterialLayerType, const TArray<struct FLandscapeLayer>* InImportLayers = nullptr);
};
.Build.cs file ↓
using UnrealBuildTool;
public class Project : ModuleRules
{
public Project(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
PrivateIncludePaths.AddRange(
new string[] {
"E:/Program Files/Epic Games/UE_5.0/Engine/Source/Runtime/Landscape/Private", // for Engine/Private/Collision/PhysXCollision.h
"E:/Program Files/Epic Games/UE_5.0/Engine/Source/Runtime/Engine/Private",
"E:/Program Files/Epic Games/UE_5.0/Engine/Shaders/Shared"
}
);
PrivateIncludePathModuleNames.AddRange(
new string[] {
"TargetPlatform",
"DerivedDataCache",
"Foliage",
"Renderer",
}
);
PrivateDependencyModuleNames.AddRange(
new string[] {
"Core",
"CoreUObject",
"ApplicationCore",
"Engine",
"RenderCore",
"RHI",
"Renderer",
"Foliage",
"DeveloperSettings"
}
);
if (Target.bBuildEditor == true)
{
PrivateIncludePathModuleNames.Add("LandscapeEditor");
PrivateDependencyModuleNames.AddRange(
new string[] {
"EditorFramework",
"UnrealEd",
"MaterialUtilities",
"SlateCore",
"Slate",
"GeometryCore"
}
);
CircularlyReferencedDependentModules.AddRange(
new string[] {
"UnrealEd",
"MaterialUtilities",
}
);
}
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "ProceduralMeshComponent", "MeshDescription", "StaticMeshDescription", "ApplicationCore", "Landscape", "LandscapeEditor", "Foliage", "Renderer", "RenderCore", "RHI", "DeveloperSettings" });
}
}
I should have added the Landscape module to the build module settings, but I cannot link (access) the functions in the module. I am so confused by this.
Even after adding LANDSCAPE_API to the functions defined in the engine source (three functions mentioned earlier) and compiling, the following error occurred.
Error: GenerateHeightmapMips(maybe) ↓
GenerateLandscape.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __cdecl ULandscapeComponent::GenerateHeightmapMips(class TArray<struct FColor *,class TSizedDefaultAllocator<32> > &,int,int,int,int,struct FLandscapeTextureDataInfo *)" (__imp_?GenerateHeightmapMips@ULandscapeComponent@@QEAAXAEAV?$TArray@PEAUFColor@@V?$TSizedDefaultAllocator@$0CA@@@@@HHHHPEAUFLandscapeTextureDataInfo@@@Z) referenced in function "public: void __cdecl UGenerateLandscape::Import(struct FGuid const &,int,int,int,int,int,int,class TMap<struct FGuid,class TArray<unsigned short,class TSizedDefaultAllocator<32> >,class FDefaultSetAllocator,struct TDefaultMapHashableKeyFuncs<struct FGuid,class TArray<unsigned short,class TSizedDefaultAllocator<32> >,0> > const &,wchar_t const * const,class TMap<struct FGuid,class TArray<struct FLandscapeImportLayerInfo,class TSizedDefaultAllocator<32> >,class FDefaultSetAllocator,struct TDefaultMapHashableKeyFuncs<struct FGuid,class TArray<struct FLandscapeImportLayerInfo,class TSizedDefaultAllocator<32> >,0> > const &,enum ELandscapeImportAlphamapType,class TArray<struct FLandscapeLayer,class TSizedDefaultAllocator<32> > const *)" (?Import@UGenerateLandscape@@QEAAXAEBUFGuid@@HHHHHHAEBV?$TMap@UFGuid@@V?$TArray@GV?$TSizedDefaultAllocator@$0CA@@@@@VFDefaultSetAllocator@@U?$TDefaultMapHashableKeyFuncs@UFGuid@@V?$TArray@GV?$TSizedDefaultAllocator@$0CA@@@@@$0A@@@@@QEB_WAEBV?$TMap@UFGuid@@V?$TArray@UFLandscapeImportLayerInfo@@V?$TSizedDefaultAllocator@$0CA@@@@@VFDefaultSetAllocator@@U?$TDefaultMapHashableKeyFuncs@UFGuid@@V?$TArray@UFLandscapeImportLayerInfo@@V?$TSizedDefaultAllocator@$0CA@@@@@$0A@@@@@W4ELandscapeImportAlphamapType@@PEBV?$TArray@UFLandscapeLayer@@V?$TSizedDefaultAllocator@$0CA@@@@@@Z)
Error: GenerateWeightmapMips(maybe) ↓
GenerateLandscape.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: static void __cdecl ULandscapeComponent::GenerateWeightmapMips(int,int,class UTexture2D *,struct FColor *)" (__imp_?GenerateWeightmapMips@ULandscapeComponent@@SAXHHPEAVUTexture2D@@PEAUFColor@@@Z) referenced in function "public: void __cdecl UGenerateLandscape::Import(struct FGuid const &,int,int,int,int,int,int,class TMap<struct FGuid,class TArray<unsigned short,class TSizedDefaultAllocator<32> >,class FDefaultSetAllocator,struct TDefaultMapHashableKeyFuncs<struct FGuid,class TArray<unsigned short,class TSizedDefaultAllocator<32> >,0> > const &,wchar_t const * const,class TMap<struct FGuid,class TArray<struct FLandscapeImportLayerInfo,class TSizedDefaultAllocator<32> >,class FDefaultSetAllocator,struct TDefaultMapHashableKeyFuncs<struct FGuid,class TArray<struct FLandscapeImportLayerInfo,class TSizedDefaultAllocator<32> >,0> > const &,enum ELandscapeImportAlphamapType,class TArray<struct FLandscapeLayer,class TSizedDefaultAllocator<32> > const *)" (?Import@UGenerateLandscape@@QEAAXAEBUFGuid@@HHHHHHAEBV?$TMap@UFGuid@@V?$TArray@GV?$TSizedDefaultAllocator@$0CA@@@@@VFDefaultSetAllocator@@U?$TDefaultMapHashableKeyFuncs@UFGuid@@V?$TArray@GV?$TSizedDefaultAllocator@$0CA@@@@@$0A@@@@@QEB_WAEBV?$TMap@UFGuid@@V?$TArray@UFLandscapeImportLayerInfo@@V?$TSizedDefaultAllocator@$0CA@@@@@VFDefaultSetAllocator@@U?$TDefaultMapHashableKeyFuncs@UFGuid@@V?$TArray@UFLandscapeImportLayerInfo@@V?$TSizedDefaultAllocator@$0CA@@@@@$0A@@@@@W4ELandscapeImportAlphamapType@@PEBV?$TArray@UFLandscapeLayer@@V?$TSizedDefaultAllocator@$0CA@@@@@@Z)
Error: UpdateCollisionHeigthData(maybe) ↓
GenerateLandscape.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __cdecl ULandscapeComponent::UpdateCollisionHeightData(struct FColor const *,struct FColor const *,int,int,int,int,bool,struct FColor const *,bool)" (__imp_?UpdateCollisionHeightData@ULandscapeComponent@@QEAAXPEBUFColor@@0HHHH_N01@Z) referenced in function "public: void __cdecl UGenerateLandscape::Import(struct FGuid const &,int,int,int,int,int,int,class TMap<struct FGuid,class TArray<unsigned short,class TSizedDefaultAllocator<32> >,class FDefaultSetAllocator,struct TDefaultMapHashableKeyFuncs<struct FGuid,class TArray<unsigned short,class TSizedDefaultAllocator<32> >,0> > const &,wchar_t const * const,class TMap<struct FGuid,class TArray<struct FLandscapeImportLayerInfo,class TSizedDefaultAllocator<32> >,class FDefaultSetAllocator,struct TDefaultMapHashableKeyFuncs<struct FGuid,class TArray<struct FLandscapeImportLayerInfo,class TSizedDefaultAllocator<32> >,0> > const &,enum ELandscapeImportAlphamapType,class TArray<struct FLandscapeLayer,class TSizedDefaultAllocator<32> > const *)" (?Import@UGenerateLandscape@@QEAAXAEBUFGuid@@HHHHHHAEBV?$TMap@UFGuid@@V?$TArray@GV?$TSizedDefaultAllocator@$0CA@@@@@VFDefaultSetAllocator@@U?$TDefaultMapHashableKeyFuncs@UFGuid@@V?$TArray@GV?$TSizedDefaultAllocator@$0CA@@@@@$0A@@@@@QEB_WAEBV?$TMap@UFGuid@@V?$TArray@UFLandscapeImportLayerInfo@@V?$TSizedDefaultAllocator@$0CA@@@@@VFDefaultSetAllocator@@U?$TDefaultMapHashableKeyFuncs@UFGuid@@V?$TArray@UFLandscapeImportLayerInfo@@V?$TSizedDefaultAllocator@$0CA@@@@@$0A@@@@@W4ELandscapeImportAlphamapType@@PEBV?$TArray@UFLandscapeLayer@@V?$TSizedDefaultAllocator@$0CA@@@@@@Z)
Finish Output:
C:\Users\User\Documents\Unreal Projects\Project\Binaries\Win64\UnrealEditor-Project.patch_0.exe : fatal error LNK1120: 3 unresolved externals
Failed to link patch (0.000s) (Exit code: 0x460)
Sorry for the long sentence. We would like to thank all the great Unreal Engine developers for their help.