How to sort actors detected by line trace?

I’m now developing a logic that detects the terrain(floor, ground, sea…etc) directly below an object/character and then returns the current terrain type which would be converted to differnt numbers (enum?) later. I use the c++ version for SingleLineTraceByChannel to detect the terrain actors and I am now confused as to what logic I should use to differentiate them.
It seems that using ‘actor tag’ to sort is a disaster because I have to apply many ‘hasTag’ functions to check all the tag I defined for the terrains. Any good idea? Thanks.

You can use the surface type of the physical material from the hit result to determine what type of terrain you hit. The surface type is just a byte, so it’s already a number. You can use that number as an index to pick the appropriate assets for that terrain (e.g. picking a sound from an array of sounds).

Example in blueprints, but same goes for c++:

You set the names of the surface types in the project settings under physics:
image

You set the physical material for a material in the material editor:
image


Also, if you’re using the character movement component, instead of doing a line trace, you can use CurrentFloor to get what the character is standing on currently.

1 Like