Getting splines to stick to the ground

Is there a way to have splines snap to the ground, no matter if there are hills or valleys?

Anyone know?

Are you trying to snap at runtime or in the editor?

In the editor. I’m trying to make roads that stick to the ground, no matter the angle.

If your spline is part of a blueprint with a spline component, you can have the construction script send a trace down from your spline point and set that spline point’s Z to the trace’s impact position’s Z.

Not exactly sure what all that means, but I’ll see if I can figure it out from what you’ve given me.

Ok so you know how blueprints have two tabs by default in the graph view, Event Graph and Construction Script?

The construction script is where you can run blueprint scripts when placing or manipulating objects in the editor viewport.

I put together the script for you, but there’s a problem. It should work theoretically, but does not in 4.7 preview presumably because of “UE-9724 Actor rerun construction script doesn’t run when making changes to components.”

I haven’t tried it in 4.6, but it might work for you there.


On running construction script, check if public boolean “execute” is true. If so, run a for loop from 0 to number of spline points - 1, firing a trace from each spline point’s X and Y at StartZ (I used 10000) to each spline point’s X and Y and EndZ (I used -1000). If the trace hits something, Set World Location at Spline Point to its current X and Y at the hit location’s (or Impact point’s) Z plus OffsetZ. When the loop is completed, set “execute” to false.

Then when you want to snap the spline, just set “execute” to true from the Details pane in the map tab.

EDIT: tried it in 4.6, no dice. Could someone else chime in with a peer review of my script? Maybe I’m missing something.

SOLVED! This method actually works, but make sure that when you add the spline component in the blueprint … on that spline’s details panel you check the box called “input spline points to construction script”. Until you do this you will see the ray trace hit the ground but the spline will not move. Let me know if you have any issues! :wink: 6bbc63c48e97ef80849136ee0a41789b6a37f7aa.png

Hi, i’m not able to micmic that is Unreal 4.24, 2 years laters. Can anybody update that nodal with the recents nodes please? Thank you very much.

The nodes should be the same also the logic. the problem still exists, there is no other way currently