Can you give me an example of SplineMeshComponent in C++?

Here is how I do it :

void ARaceSpline::OnConstruction(const FTransform& Transform)
{
	for (int32 i = 0; i < mSplineComponent->GetNumSplinePoints() - 1; i++)
	{
		USplineMeshComponent* SplineMesh = ConstructObject<USplineMeshComponent>(USplineMeshComponent::StaticClass(), this);

		SplineMesh->bCreatedByConstructionScript = true;
		SplineMesh->SetMobility(EComponentMobility::Movable);
		SplineMesh->AttachParent = mSplineComponent;

		//Set the color!
		UMaterialInstanceDynamic* dynamicMat = UMaterialInstanceDynamic::Create(mSplineMeshMaterial, NULL);
		dynamicMat->SetVectorParameterValue(TEXT("Color"), FLinearColor(mSegments[i].mColor));

		SplineMesh->bCastDynamicShadow = false;
		SplineMesh->SetStaticMesh(mGridMesh);
		SplineMesh->SetMaterial(0, dynamicMat);

		//Width of the mesh 
		SplineMesh->SetStartScale(FVector2D(50, 50));
		SplineMesh->SetEndScale(FVector2D(50, 50));
		
		FVector pointLocationStart, pointTangentStart, pointLocationEnd, pointTangentEnd;
		mSplineComponent->GetLocalLocationAndTangentAtSplinePoint(i, pointLocationStart, pointTangentStart);
		mSplineComponent->GetLocalLocationAndTangentAtSplinePoint(i + 1, pointLocationEnd, pointTangentEnd);

		SplineMesh->SetStartAndEnd(pointLocationStart, pointTangentStart, pointLocationEnd, pointTangentEnd);
	}

	RegisterAllComponents();
}

What seems to be missing in your case is the actual SplineMesh Component creation. Hope this code helps you :slight_smile:

1 Like