Get a landscape layer under character

I need to know a material under my character. I am doing line trace, and trying to get this information from overlapped landscape, but I don’t know how to do it. Is there a way to get this information?

Hi Chernoburk … You can accomplish this by using Surface Types and Physical Materials…

Step 1: Go to your Project Settings → Engine → Physics section and add some custom Surface Types under the “Physical Surface” section such as Dirt, Sand, Water, Mud, Grass etc. You can make up to 62 different surface types here.

Step 2: Make a folder in your content browser to house your Physical Materials. Right-click and create a new Physical Material under the Physics category for each surface type you made in step 1. For example, PM_Mud can describe how much friction (slipperiness) and restitution (bounciness) you’ll get when you apply this to muddy surfaces. The important step here though is to change the “Surface Type” drop-down to match the right surface type from earlier. Ex: In this example, set it to “Mud”.

Step 3: When you setup your LandscapeLayerInfo for each landscape layer on your terrain, be sure to set the “Physics Material” there to one of your custom PMs from step 2. This is how you link a landscape layer to a physical material which then links back to a surface type.

Step 4: Now in your character blueprint (or better yet its Animation BP), you can run a LineTraceByChannel from your pawn to a point below the terrain against the Visibility channel. [Make sure you check on Ignore Self, and depending on how you want to do it - you may need to create your own custom trace channels which ignore foliage and other stuff that might get in the way]. Off of the blue Out Hit pin, drag off and select “Get Surface Type”. This will give you an enumeration of the 62 surface types from step 1 which you can Switch off of or send into an audio system to play a specific footstep or whatever you want.

Hope this helps!

7 Likes

Hey, first comment here. Just want to say that this worked like a charm! Hope this answer gets a bit more attention from Google now. Please mark it as solved if this worked for you as well.