Spline mesh component doesn't join up correctly

Hey all!

I was trying to implement a spline mesh system with C++, and I’m having some trouble I can’t figure the cause of.

So, I started by following this BP tutorial.

It worked great, I tested my mesh with it, works as well.

So now I’m trying to implement something similar in C++. I’m gonna be needing to add and remove segments of pipes during gameplay, so I’ve got a function to add individual pieces :

void ASplineObjectTrackGenerator::AddSplineMeshSegment()
	SplineMeshComponents.Add(ConstructObject<USplineMeshComponent>(USplineMeshComponent::StaticClass(), this));
	USplineMeshComponent* presentSplineMeshComp = SplineMeshComponents.Last();
	presentSplineMeshComp->SetStartScale(FVector2D(10, 10));
	presentSplineMeshComp->SetEndScale(FVector2D(10, 10));
	FVector pointLocationStart, pointTangentStart, pointLocationEnd, pointTangentEnd;
	float startDist, endDist;

	if (SplineMeshComponents.Num() == 1)
		pointLocationStart = SplineComponent->GetLocationAtDistanceAlongSpline(0, ESplineCoordinateSpace::Local);
		pointTangentStart = SplineComponent->GetTangentAtDistanceAlongSpline(0, ESplineCoordinateSpace::Local);
		pointLocationEnd = SplineComponent->GetLocationAtDistanceAlongSpline(pipeSegmentLength, ESplineCoordinateSpace::Local);
		pointTangentEnd = SplineComponent->GetTangentAtDistanceAlongSpline(pipeSegmentLength, ESplineCoordinateSpace::Local);

		startDist = 0;
		endDist = pipeSegmentLength;

	else if (SplineMeshComponents.Num() > 1)
		USplineMeshComponent* previousSplineMesh = SplineMeshComponents[SplineMeshComponents.Num() - 2];
		startDist = (SplineMeshComponents.Num() - 1) * pipeSegmentLength;
		float newDist = startDist + pipeSegmentLength;
		endDist = newDist;

		pointLocationStart = SplineComponent->GetLocationAtDistanceAlongSpline(startDist, ESplineCoordinateSpace::Local);
		pointTangentStart = SplineComponent->GetTangentAtDistanceAlongSpline(startDist, ESplineCoordinateSpace::Local);

		pointLocationEnd = SplineComponent->GetLocationAtDistanceAlongSpline(newDist, ESplineCoordinateSpace::Local);
		pointTangentEnd = SplineComponent->GetTangentAtDistanceAlongSpline(newDist, ESplineCoordinateSpace::Local);

	presentSplineMeshComp->SetStartAndEnd(pointLocationStart, pointTangentStart, pointLocationEnd, pointTangentEnd);
	presentSplineMeshComp->startDistance = startDist;
	presentSplineMeshComp->endDistance = endDist;

	while (SplineMeshComponents.Num() > maxNumberOfMeshSegments)


StartDistance and endDistance are two public variable I stapled on SplineMeshComponent to track where my splines start and begin more easily. Also, you’ll notice that all my pipes are the same length along the spline, instead of just starting and ending on the spline points.

Now, concerning my issue. The spline mesh components seem to have messed up tangents for some reason. (The mesh is a pipe with only inside-facing normals visible.)

Basically, the edges of the pipe don’t match up, even though the tangents and the locations of the spline mesh components do (I verified with a print to screen). Remember, on the blueprint based function, the meshes meshed perfectly.

Any ideas? Am I doing something horribly wrong?

If you imagine each mesh segment as a circle extruded along the spline segment, then this is perfectly normal.