USplineComponent :: Get Location At Distance Along Spline doesn't compute correctly when using closed loop

    Spline = NewObject<USplineComponent>(bspline);
    Spline->SetWorldLocation(FVector::ZeroVector);
    Spline->bAllowDiscontinuousSpline = true;

    Spline->SetLocationAtSplinePoint(0, rectBL, ESplineCoordinateSpace::World);
    Spline->SetTangentsAtSplinePoint(0, FVector::ZeroVector, FVector::ZeroVector, ESplineCoordinateSpace::Local);
    Spline->SetLocationAtSplinePoint(1, rectBR, ESplineCoordinateSpace::World);
    Spline->SetTangentsAtSplinePoint(1, FVector::ZeroVector, FVector::ZeroVector, ESplineCoordinateSpace::Local);
    Spline->AddSplinePoint(rectTR, ESplineCoordinateSpace::World);
    Spline->SetTangentsAtSplinePoint(2, FVector::ZeroVector, FVector::ZeroVector, ESplineCoordinateSpace::Local);
    Spline->AddSplinePoint(rectTL, ESplineCoordinateSpace::World);
    Spline->SetTangentsAtSplinePoint(3, FVector::ZeroVector, FVector::ZeroVector, ESplineCoordinateSpace::Local);
    Spline->SetClosedLoopAtPosition(true, 0);

float distance = Spline->GetSplineLength();
	const int numPts = 25;
	for (int i = 0; i < numPts; ++i)
	{
		float unitDist = (distance / numPts) * i;
		auto unit = Spline->GetLocationAtDistanceAlongSpline(unitDist, ESplineCoordinateSpace::World);
	}

If you watch the unit value as it iterates, it stops increasing as expected when your location is between the last point and the first point that would close the loop. So it reports the same position for any distance that would be between points 4 and 0 in this case. This example shows a square with no tangent vectors and it reports a correct length of 400 so it knows it’s close and to include that edge in the length calculation.

I take back everything I said. The problem is SetClosedLoopAtPosition(true, 0) Closing the loop on the first point is wrong. It looks right since it will actually close the loop visually, but you have to set the position to the number of points in the spline which seems like it’d be an out of range error but the engine code handles it correctly. So if anyone else falls down this rabbit hole you’ll get correct distances all the way around a closed loop if you close it on Spline->GetNumberOfSplinePoints()