Closest position on a Spline to a Player

Except SplineMeshComponent doesn’t actually expose the underlying SplineComponent needed to call that function.
Why? Beats me, but that’s the state.

You can also just add some movement input to make the character keep walking towards the location you want. In Tick, figure out how close you are, and which way you need to walk/turn to get where you need to go, and call AddMovementInput on the CharacterMovementComponent to move/turn appropriately.

1 Like

Reading the code, it doesn’t actually use a SplineComponent; instead it implements a single spline segment with entry and exit tangents, manually.
So, the SplineMeshComponent is only really useful to deform a single static mesh, and then only when that mesh is sufficiently tesselated to do well with such a deformer.

The common case of “place a mesh (or variety of meshes) along a spline” isn’t actually natively built-in; you’ll have to use the SplineComponent on an Actor with a InstancedStaticMesh component, and add instances along the spline in the construction script.

In general, it seems there are two parameters that let you index along the SplineComponent, one is InputKey which is really a floating point index into the points of the spline – values in [0.0 .. 1.0) indexes between first and second point, [1.0 .. 2.0) indexes between second and third point, and so on. There’s also DistanceAlongSpline which indexes based on measured world-space distance. Most of the Spline value lookup functions (get transform, get direction, and so on) can take one or the other (or both.)

1 Like