# What are spline input keys?

There isn't a really adequate explanation of these anywhere on the internet, so I thought I'd ask this question here.

• What are spline input keys in Unreal?

• How are they represented in Unreal?

Also:

• FindInputKeyClosestToWorldLocation returns a float.
• What is this return value?
• Why is it a float?

A spline key input is a bit like an index into the spline. A spline is generally formed from control points, similar to a Bezier curve. My knowledge on this is rusty, but the idea seems to be that the starting point has the value of 0.0f, and is increased by 1.0f (by default) per point, so a minimal spline out of two points goes from 0.0f to 1.0f while one made of 4 points would go from 0.0f to 3.0f, with the intermediate points having the values 1.0f and 2.0f.

Why a float? So that you can point at somewhere between the control points and ask what the value there is. In the case of our simplest spline, "two-thirds through" would correspond to 0.67f. This value basically encodes two things in one in a way - the integer part selects the two points between which the interpolation happens (0.67f => points 0 and 1) and the fractional part selects the amount of interpolation (.67 => 33% of point 0, 67% of point 1).

FindInputKeyClosestToWorldLocation - this function takes a world location and finds the closest point on the selected spline to that location. It then determines the input key value and returns it.

Here's a mediocre visual drawn in Paint: Here, a spline is drawn in green, with two points (0 and 1) being its control points. A point A is selected. What the function does is find the point B on the spline which is the closest to point A. Then it determines the value of the key input at the point B, which appears to be roughly halfway through, corresponding to around 0.5f.

If I understand it correctly, it is possible to specify your own values for key input on the points, so a 4-point spline can go from 0.0f to 1.0f with the two midway points being at 0.25f and 0.75f or even having their own custom values.