[UE5.6] How to draw path preview?

I’m making a tower defense game and explaining what I want is rather simple. Enemies enter via a door and exit via a gate. When I press Tab, I want to see the path the enemies will take. This is a dynamic path since building towers can alter the path the enemies take.

I’m using a nav mesh to query the path since I want to show the exact same path as in the game. But when I ask for a path, it doesn’t seem bothered by elevation changes. So if there’s a path in a straight line that goes up and down, I’ll only get a point at the start and one point at the end of the straight path.

I’m using a spline mesh component to show the path. Having the spline go through and under the road isn’t a good look.

I’ve thought about using a FInterpCurveVector and sampling points along the curve to get the proper elevation. But that could add delays and help people cheat. Maybe it won’t be a problem. I think knowing where the road changes elevation is the tough part.

I do have an in-memory map of the grid and paths. I use it to check if the path would be blocked when building a tower. But using it here is not so obvious.

Here’s a screenshot of some of the points on the path.

There are 3 paths. The green spheres show points on the path (elevated by 50cm). You can see all 3 paths have ZERO points when the elevation changes. It knows the elevation changes. But it doesn’t care. The middle path (yellow borders) is especially bad. You can see the blue preview spline goes completely under the road.

The nav mesh itself follows the elevation changes perfectly.

Anyone have any ideas how to make the preview path follow the surface of the roads?

After writing it all out, my best idea right now is to compare heights of every pair of points. If the heights are different, then I need to do some line traces in between the points to add points at their proper heights. The problem is I have a path that goes down and back up. So both endpoints are at exactly the same height and that means this idea won’t work for that segment.

For anyone who runs into a similar situation, I took all the points and put them into a FInterpCurveVector. I had to loop over the points to find the total distance first in order to get a percentage value to used with the curve class on each point.

Then I calculated the increment used for 100cm. I then did a line trace every 100cm to find the height. I also grouped the line trace hit results by actor that it hit. So if it’s a straight line, I remove all the points in between the end points. For curves, I used circular regression to smooth out the curve. And if it has 2 points or less, I just copy them over.

This is what I got:

Works great. Most of my paths are 100 tiles long. So about 350 line traces. And the geometry for the roads are extremely simple. I didn’t notice any performance issues at all.