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"

Office Holiday

Epic Games' offices will be on holiday from June 22nd to July 7th. During this period support will be limited. Our offices will reopen on Monday, July 8th. 

How to read landscape heightmap at runtime?

I want to read Landscape altitude (z value) given 2D coordinates (x and y values) from another actor at runtime.

  • Do I need a ALandscape* reference to access its properties? I tried to set Landscape object to that pointer using Blueprint but I got an error (ALandscape scene actor is private and cannot be reached by other actors). What am mistaken?

  • at first sight I founded a very long chain to reach something similar to what I'm asking

LandscapeProxy::GetLandscapeInfo()->XYtoComponentMap()[x,y]->HeightmapTexture->GetSurfaceHeight() or should I look somewhere else? anyway I'm not even sure about resolution of this value (does it returns the average height of the tile? the maximum?) Is there a way to find the exact z value?

All of this because I want to spawn an actor just a few meters above the terrain. I guess there is an easier way to do that...

Product Version: Not Selected
more ▼

asked Jul 22 '14 at 12:48 AM in C++ Programming

avatar image

73 4 9 12

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

3 answers: sort voted first

I recently had a similar problem and stumbled across this post. Now I have found a solution, so here it is:

First you need to somehow get an instance to your landscape (assuming you only have one in your level):

 #include "Landscape/Landscape.h"
 UWorld* world = GetWorld();
 if (world == nullptr)
 // Find the active landscape
 TActorIterator<ALandscape> landscapeIterator(world);
 ALandscape* landscape = *landscapeIterator;

Now you can do a line trace where you only look at the landscape and no other object in the scene. The internal physx collision object is initialized from the heightmap data, so this line trace should be very fast and in theory it should have almost the same speed as doing a heightmap lookup:

 FCollisionQueryParams collisionParams(FName(TEXT("FoliageClusterPlacementTrace")), true, this);
 collisionParams.bReturnPhysicalMaterial = true;
 FHitResult hit(ForceInit);
 if (landscape->ActorLineTraceSingle(hit, rayStart, rayEnd, ECC_Visibility, collisionParams)) {
     // Do something

more ▼

answered Oct 25 '14 at 04:32 PM

avatar image

90 7 9 109

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

My solution...

alt text


alt text

on world.png (334.4 kB)
altitude at.png (414.4 kB)
more ▼

answered May 08 '15 at 07:01 PM

avatar image

SND R Keene
963 31 120 113

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

I know this is Unreal Engine, but when i was unity, the landscape had a mesh component. So try getting a reference to the mesh component of the landscape. It should have some kind of property that you can get the z component, given an x-y coordinates.

Edit: Ill try it out when i get home on my project.

more ▼

answered Jul 25 '14 at 08:44 PM

avatar image

136 11 17 22

avatar image keru Jul 28 '14 at 01:58 PM

Thanks, let me know.

avatar image Makotech222 Jul 28 '14 at 02:03 PM

I've failed you lol. I tried to get coordinate data but it wasn't working out. Sorry!

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
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