RealDocs

USplineMeshComponent

class Engine Blueprint Since 4.0
#include "Components/SplineMeshComponent.h"

Description

A static mesh component that deforms its mesh along a local spline segment, stretching or bending it between two defined points. Used to construct roads, pipes, rails, and cables from tile meshes.

Caveats & Gotchas

  • USplineMeshComponent deforms a single mesh segment between StartPos/StartTangent and EndPos/EndTangent — it does not read from a USplineComponent automatically. You must drive the parameters yourself, typically by iterating USplineComponent::GetLocationAtSplinePoint and GetTangentAtSplinePoint.
  • The deformation is a vertex shader operation. Very high-poly source meshes will not deform well. Use a low-poly cylindrical mesh for best results.
  • Collision is static by default. If the spline changes at runtime, call UpdateMesh() and RecreateCollision() to keep collision in sync.

Example

Spawn one SplineMeshComponent per segment of a spline C++
int32 NumPoints = SplineComp->GetNumberOfSplinePoints();
for (int32 i = 0; i < NumPoints - 1; ++i)
{
    USplineMeshComponent* SMC = NewObject<USplineMeshComponent>(this);
    SMC->SetStaticMesh(RailMesh);
    SMC->SetMobility(EComponentMobility::Movable);
    SMC->RegisterComponent();

    FVector StartPos, StartTangent, EndPos, EndTangent;
    SplineComp->GetLocationAndTangentAtSplinePoint(i,   StartPos, StartTangent, ESplineCoordinateSpace::Local);
    SplineComp->GetLocationAndTangentAtSplinePoint(i+1, EndPos,   EndTangent,   ESplineCoordinateSpace::Local);
    SMC->SetStartAndEnd(StartPos, StartTangent, EndPos, EndTangent);
}

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.