Access to landscape in C++

Hi,
I am trying to make some procedural alghoritms in C++, but I can’t get access to landscape (to read hightmap or align objects to it). I was trying something like this:

#include "Classes/Landscape.h"

AEditorTerr::AEditorTerr()
{
	PrimaryActorTick.bCanEverTick = true;
	TActorIterator<ALandscape> landIterator(GetWorld());
}

And i get error:

unresolved external symbol
“__declspec(dllimport) private: static
class UClass * __cdecl
ALandscape::GetPrivateStaticClass(wchar_t
const *)”
(_imp?GetPrivateStaticClass@ALandscape@@CAPEAVUClass@@PEB_W@Z)
referenced in function “public:
__cdecl AEditorTerr::AEditorTerr(void)”
(??0AEditorTerr@@QEAA@XZ)

Any solution for this?

Hey!

First: because of reflection system i highly recommend to not do that in constructor :slight_smile:

Ues reflection system will read and compile constructors for blueprint system when engine start.
If youcall getworld there or try to get any actor will cause possiblr crash.

Override OnConstruction(FTransform Transform) function in your actor,which will execute only when actor are placed on level, or moved or something :slight_smile:

Second: i recommend to use UGameplayStatistics::GetAllActorOfClass
Which will give back an actor array what are placed in world :slight_smile:

Third: if this will be some kind of editor extra feature and will not used ingame/runtime i suggest to start learn how to extend editor.
Because Editor has LOT OF feature to search/select/deselect actors from current level, which can be usefull if you want extend editor…
Of course for this you need do Plugin instead of simple project :slight_smile: some doc about that: https://docs.unrealengine.com/latest/INT/Videos/PLZlv_N0_O1ga0aV9jVqJgog0VWz1cLL5f/zg_VstBxDi8/

Hi,

Thank you for your answer. Well, I didn’t want it to work in this place :slight_smile: I am only trying to resolve my problem, no matter where, but thank you so much for your tips for the future.

Unfortunately it doesn’t help me :frowning:

void AEditorTerr::OnConstruction(const FTransform& Transform) {
	TArray<AActor*> lands;
	UGameplayStatics::GetAllActorsOfClass(GetWorld(), ALandscape::StaticClass(), lands);
}

Still same error:

unresolved external symbol
“__declspec(dllimport) private: static
class UClass * __cdecl
ALandscape::GetPrivateStaticClass(wchar_t
const *)”
(_imp?GetPrivateStaticClass@ALandscape@@CAPEAVUClass@@PEB_W@Z)
referenced in function “public:
virtual void __cdecl
AEditorTerr::OnConstruction(struct
FTransform const &)”
(?OnConstruction@AEditorTerr@@UEAAXAEBUFTransform@@@Z)

Is header file correct?

#include "Classes/Landscape.h"

I tried other classes like AStaticMeshActor and problem didn’t occur.

Try include this

 #include "Landscape/Landscape.h"

There is no path like this. I get

#include "Runtime/Landscape/Classes/Landscape.h"

but still the same

Ahhh ahhh ahh, i know what is the problem :slight_smile:
You need add “Landscape” module in your project build settings i guess

1 Like

If anybody finds this:

I had to add “Landscape” as an dependency in my Build.cs file since it is not an internal module. after that, I resolved some erros.

Still having a hard time with landscapes and c++