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!
3 Likes