Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Landscape Heightmap in C++

I'm really new to programming in C++ in UE4, and all I want to do is bring in the landscape heightmap and read it programmatically to then place collision boxes on it at equal distances (in like a grid). Everything else I need to do at the moment can be done via the editor using blueprints etc.

So I've spent the last two days looking through the code, blowing my mind up with its complexity and lack of real documentation for landscapes. So far I have the following code to bring in the heightmap - just some slightly altered lines from the methods SplitHeightMap() in LandscapeEdMode.cpp and ExportHeightmap() in LandscapeEdit.cpp:

 #include "LandscapeCollision.h"
 #include "LandscapeEdit.h"
 #include "LandscapeInfo.h"
 #include "Landscape.h"
 #include "EngineUtils.h"
 void ALandscapeCollision::importHeightMap()
     int32 MinX = MAX_int32;
     int32 MinY = MAX_int32;
     int32 MaxX = -MAX_int32;
     int32 MaxY = -MAX_int32;
     UWorld* World = GetWorld();
     LANDSCAPE_API ULandscapeInfo* landscapeInfo;
     for (TActorIterator<ALandscape> ALandscapeItr(World); ALandscapeItr; ++ALandscapeItr)
         landscapeInfo = ALandscapeItr->GetLandscapeInfo();
         FLandscapeEditDataInterface landscape(landscapeInfo);
         TArray<uint16> HeightData;
         HeightData.AddZeroed((MaxX - MinX + 1) * (MaxY - MinY + 1));
         landscape.GetHeightDataFast(MinX, MinY, MaxX, MaxY, HeightData.GetData(), 0);
         this->heightMap = HeightData;

I'm really aware my code is far from perfect at this point.

Anyway, so far I think my main issue is correctly referencing to API_LANDSCAPE in certain places. My Build.cs file has:

         PublicDependencyModuleNames.AddRange(new string[] {
             "InputCore" });
         PrivateDependencyModuleNames.AddRange(new string[] {
             "Landscape" });

And the errors I'm coming into are along the lines of:

 CompilerResultsLog: Error: LandscapeCollision.cpp.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) class ULandscapeInfo * landscapeInfo" (__imp_?landscapeInfo@@3PEAVULandscapeInfo@@EA)

and depending on if I place LANDSCAPE_API on various lines:

 CompilerResultsLog: Error C2491: 'landscape': definition of dllimport data not allowed
 CompilerResultsLog: Error C2205: 'landscape': cannot initialize extern variables with block scope

Can anyone give me any insight into what I can do to get this code to work? Thanks so much.

Product Version: UE 4.19
more ▼

asked Mar 29 '18 at 09:45 PM in C++ Programming

avatar image

1 1 2

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question