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.
Here:
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!
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
Just because this post comes up top results in a Google Search and there’re no images in the answers anymore… here’s my solution:
This is of course added to the Event Graph of a Blueprint with a spline component. The nice thing is if you use the Call In Editor bool (select your custom event and look in the details), it gives you a handy button to call this code when you’ve got the actor selected. You can call it as many times as you like and it will simply position any newly added points on the ground as well. If your spline is incredibly complex it might take a moment to run so don’t spam the button. Also, be sure to select the all the splines and move them up a bit before you press the button, otherwise, your splines might stay below the surface if they’re already there.
(post deleted by author)