This function will copy an existing USplineComponent* and return a new one with the same attributes:
// Create a new SplineComponent and copy data from the reference to it.
UFUNCTION(Category="EXAMPLES")
FORCEINLINE USplineComponent* CopySpline(const USplineComponent* ReferenceSpline)
{
USplineComponent* NewSpline = Cast<USplineComponent>(AddComponentByClass(
USplineComponent::StaticClass(), false, FTransform(), false));
NewSpline->SetWorldTransform(ReferenceSpline->GetComponentTransform());
for (int32 i = 0; i < ReferenceSpline->GetNumberOfSplinePoints(); i++)
{
FVector Location = ReferenceSpline->GetLocationAtSplinePoint(
i, World) - FVector(0.0, 0.0, 100.0);
FRotator Rotation = ReferenceSpline->GetRotationAtSplinePoint(
i, World);
auto ArriveTangent = ReferenceSpline->GetArriveTangentAtSplinePoint(
i, World);
auto LeaveTangent = ReferenceSpline->GetLeaveTangentAtSplinePoint(
i, World);
auto UpVector = ReferenceSpline->GetUpVectorAtSplinePoint(
i, World);
// Set spline points (and add if needed)
if (i > 1)
NewSpline->AddSplinePoint(Location, World);
else
NewSpline->SetLocationAtSplinePoint(i, Location, World);
NewSpline->SetRotationAtSplinePoint(i, Rotation, World);
NewSpline->SetTangentsAtSplinePoint(i, ArriveTangent, LeaveTangent, World);
NewSpline->SetUpVectorAtSplinePoint(i, UpVector, World);
// Colors
NewSpline->SetTangentColor(DefaultColor);
NewSpline->SetSelectedSplineSegmentColor(DefaultColor);
NewSpline->SetUnselectedSplineSegmentColor(DefaultColor);
}
NewSpline->SetClosedLoop(ReferenceSpline->IsClosedLoop());
return NewSpline;
}