转自:http://aigo.iteye.com/blog/2279503
void ARaceSpline::OnConstruction(const FTransform& Transform)
{
for (int32 i = ; i < mSplineComponent->GetNumSplinePoints() - ; 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(, dynamicMat); //Width of the mesh
SplineMesh->SetStartScale(FVector2D(, ));
SplineMesh->SetEndScale(FVector2D(, )); FVector pointLocationStart, pointTangentStart, pointLocationEnd, pointTangentEnd;
mSplineComponent->GetLocalLocationAndTangentAtSplinePoint(i, pointLocationStart, pointTangentStart);
mSplineComponent->GetLocalLocationAndTangentAtSplinePoint(i + , pointLocationEnd, pointTangentEnd); SplineMesh->SetStartAndEnd(pointLocationStart, pointTangentStart, pointLocationEnd, pointTangentEnd);
} RegisterAllComponents();
}