How can I find index of closest spline point using time or distance

You have to interate over the spline points using a for loop. GetNumberOfSplinePoints give you how many points and GetDistanceAlongSplineAtSplinePoint will tell you how far the point is along the spline.

You need to get through all the points and find the nearest one to your current distance…

Thanks for answer I tried this way, but there are thousands of points in the spline and this is meaning very low fps. is there a way to do this without fps dropping.

What are you trying to do, in general terms? How did you arrive at needing to find the nearest spline point…?

This is highly un-scientific and could lead to the wrong result if your spline twists back onto itself or has a crazy shape (ie: you might return a local optima but not the very best solution)… but anyways food for thought in case there are no better ideas: Let’s say you have exactly 1,000 spline points for this example. Divide that set into 10 equal segments and test every hundredth point, as in #0, #100, #200, #300 thru #1000 to find the closest one. Let’s say #700 is the answer. Now drop down and test every tenth point centered from there, such as #650, #660, #670 thru #750. Let’s say #670 is the new answer. Drop one final time and test every point centered on that, from #665 thru #675. Now you’ve found a very close spline point in just 33 tests instead of 1,000… which should run much faster.

What’s highly unscientific is giving this person an algorithm for missile guidance when all they wanted was to search along a spline.

Now that we know the spline has many points, maybe it’s worth looking into.

Reading the distance in world space copes with any shaped spline.

for location based finding of spline points i know that you could use the find input key closest to world location node. it will actually return the closest point on the spline in terms of points. so if you were between point 3 and 4 it would return a value of 3.x where x is how far from point 3 you were, ie if you were halfway then it would be 3.5. you could then take the value and round it to get a integer that correlates to a spline point.

aside the the location use case i haven’t used the other similar nodes. i just tried location at time node with the input key location and that one seems to work but im not sure how the time works (i think its about 0.1 time per unit of distance). the input key at distance seemed to only return a 0-1 value so it may be worth playing with but not quite what you need.