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.