UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
SplineMeshComponent.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreMinimal.h"
7#include "Misc/Guid.h"
10#include "SplineMeshShaderParams.h"
11
12#include "SplineMeshComponent.generated.h"
13
15class ULightComponent;
17class UBodySetup;
18struct FMeshDescription;
19
20// Helper for packing spline mesh shader parameters into a float4 buffer
22
23UENUM(BlueprintType)
25{
26 enum Type : int
27 {
31 };
32}
33
35{
36 ENGINE_API float RealToFloatChecked(const double Value);
37}
38
43USTRUCT()
45{
47
48
49 UPROPERTY(EditAnywhere, Category=SplineMesh)
50 FVector StartPos;
51
53 UPROPERTY(EditAnywhere, Category=SplineMesh)
54 FVector StartTangent;
55
57 UPROPERTY(EditAnywhere, Category=SplineMesh, AdvancedDisplay)
58 FVector2D StartScale;
59
61 UPROPERTY(EditAnywhere, Category=SplineMesh, AdvancedDisplay)
62 float StartRoll;
63
65 UPROPERTY(EditAnywhere, Category=SplineMesh, AdvancedDisplay, meta=(DisplayAfter="EndTangent"))
66 float EndRoll;
67
69 UPROPERTY(EditAnywhere, Category=SplineMesh, AdvancedDisplay)
70 FVector2D StartOffset;
71
73 UPROPERTY(EditAnywhere, Category=SplineMesh)
74 FVector EndPos;
75
77 UPROPERTY(EditAnywhere, Category=SplineMesh, AdvancedDisplay)
78 FVector2D EndScale;
79
81 UPROPERTY(EditAnywhere, Category = SplineMesh)
82 FVector EndTangent;
83
85 UPROPERTY(EditAnywhere, Category=SplineMesh, AdvancedDisplay)
86 FVector2D EndOffset;
87
93 UPROPERTY(EditAnywhere, Category=SplineMesh, AdvancedDisplay, meta=(ClampMin=1.0))
94 float NaniteClusterBoundsScale;
95
96
98 : StartPos(ForceInit)
99 , StartTangent(ForceInit)
100 , StartScale(ForceInit)
101 , StartRoll(0)
102 , EndRoll(0)
103 , StartOffset(ForceInit)
104 , EndPos(ForceInit)
105 , EndScale(ForceInit)
106 , EndTangent(ForceInit)
107 , EndOffset(ForceInit)
108 , NaniteClusterBoundsScale(1.0f)
109 {
110 }
111
112};
113
118UCLASS(ClassGroup=Rendering, hidecategories=(Physics), meta=(BlueprintSpawnableComponent), MinimalAPI)
119class USplineMeshComponent : public UStaticMeshComponent, public IInterface_CollisionDataProvider
120{
122
123
124 UPROPERTY(EditAnywhere, Category=SplineMesh, meta=(ShowOnlyInnerProperties))
125 FSplineMeshParams SplineParams;
126
128 UPROPERTY(EditAnywhere, Category=SplineMesh)
129 FVector SplineUpDir;
130
132 UPROPERTY(EditAnywhere, Category = SplineMesh, AdvancedDisplay)
133 float SplineBoundaryMin;
134
135 // Used to automatically trigger rebuild of collision data
136 UPROPERTY()
138
143 UPROPERTY()
144 float VirtualTextureMainPassMaxDrawDistance = 0.f;
145
146 // Navigation bounds can differ from primitive bounds since NavCollision can hold more geometry
148
149 // Physics data.
150 UPROPERTY()
152
154 UPROPERTY(EditAnywhere, Category = SplineMesh, AdvancedDisplay)
155 float SplineBoundaryMax;
156
158 UPROPERTY(EditAnywhere, Category=SplineMesh)
159 TEnumAsByte<ESplineMeshAxis::Type> ForwardAxis;
160
162 UPROPERTY(EditDefaultsOnly, Category = Spline)
164
166 UPROPERTY(EditAnywhere, Category=SplineMesh, AdvancedDisplay)
167 uint8 bSmoothInterpRollScale:1;
168
169 // Indicates that the mesh needs updating
171 uint8 bMeshDirty : 1;
172
173#if WITH_EDITORONLY_DATA
175 uint8 bSelected:1;
176#endif
177
178private:
184 UPROPERTY(EditAnywhere, Getter, Setter, Category = Collision)
185 uint8 bNeverNeedsCookedCollisionData:1;
186
187public:
189
190 //Begin UObject Interface
191 ENGINE_API virtual void Serialize(FArchive& Ar) override;
192#if WITH_EDITOR
194 ENGINE_API virtual bool IsEditorOnly() const override;
195 ENGINE_API virtual bool Modify(bool bAlwaysMarkDirty = true) override;
196 ENGINE_API virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
197#endif
198 //End UObject Interface
199
200 //~ Begin UActorComponent Interface.
201 ENGINE_API virtual TStructOnScope<FActorComponentInstanceData> GetComponentInstanceData() const override;
202 //~ End UActorComponent Interface.
203
204 ENGINE_API void ApplyComponentInstanceData(struct FSplineMeshInstanceData* ComponentInstanceData);
205
206 //Begin USceneComponent Interface
207 ENGINE_API virtual FBoxSphereBounds CalcBounds(const FTransform& LocalToWorld) const override;
208 ENGINE_API virtual FTransform GetSocketTransform(FName InSocketName, ERelativeTransformSpace TransformSpace = RTS_World) const override;
209 ENGINE_API virtual void UpdateBounds() override;
210 //End USceneComponent Interface
211
212 //Begin UPrimitiveComponent Interface
213protected:
214 ENGINE_API virtual void OnCreatePhysicsState() override;
215
216 float ComputeRatioAlongSpline(float DistanceAlong) const;
217
219 void ComputeVisualMeshSplineTRange(float& MinT, float& MaxT) const;
220
231 FBox ComputeDistortedBounds(const FTransform& InLocalToWorld, const FBoxSphereBounds& InMeshBounds, const FBoxSphereBounds* InBoundsToDistort = nullptr) const;
232
233public:
234 ENGINE_API virtual class UBodySetup* GetBodySetup() override;
235 ENGINE_API class UBodySetup* GetBodySetup() const;
236#if WITH_EDITOR
237 virtual bool ShouldRenderSelected() const override
238 {
239 return Super::ShouldRenderSelected() || bSelected;
240 }
241#endif
242 ENGINE_API virtual bool DoCustomNavigableGeometryExport(FNavigableGeometryExport& GeomExport) const override;
243 virtual float GetVirtualTextureMainPassMaxDrawDistance() const override { return VirtualTextureMainPassMaxDrawDistance; }
244 //End UPrimitiveComponent Interface
245
246 //Begin UStaticMeshComponent Interface
247public:
249protected:
250 ENGINE_API virtual FPrimitiveSceneProxy* CreateStaticMeshSceneProxy(::Nanite::FMaterialAudit& NaniteMaterials, bool bCreateNanite) override;
251 //End UStaticMeshComponent Interface
252
253 //~ Begin Interface_CollisionDataProvider Interface
254public:
255 ENGINE_API virtual bool GetPhysicsTriMeshData(struct FTriMeshCollisionData* CollisionData, bool InUseAllTriData) override;
256 ENGINE_API virtual bool ContainsPhysicsTriMeshData(bool InUseAllTriData) const override;
257 virtual bool WantsNegXTriMesh() override { return false; }
258 ENGINE_API virtual void GetMeshId(FString& OutMeshId) override;
259 ENGINE_API void GetMeshId(FString& OutMeshId) const;
260 ENGINE_API virtual bool GetTriMeshSizeEstimates(struct FTriMeshCollisionDataEstimates& OutTriMeshEstimates, bool bInUseAllTriData) const override;
261 //~ End Interface_CollisionDataProvider Interface
262
263 //~ Begin INavRelevantInterface
264 ENGINE_API virtual FBox GetNavigationBounds() const override;
265 //~ End INavRelevantInterface
266
268 ENGINE_API FSplineMeshShaderParams CalculateShaderParams() const;
269
272
274 UFUNCTION(BlueprintCallable, Category = SplineMesh)
275 ENGINE_API void UpdateMesh();
276
279
281 UFUNCTION(BlueprintCallable, Category = SplineMesh)
282 ENGINE_API FVector GetStartPosition() const;
283
285 UFUNCTION(BlueprintCallable, Category=SplineMesh)
286 ENGINE_API void SetStartPosition(FVector StartPos, bool bUpdateMesh = true);
287
289 UFUNCTION(BlueprintCallable, Category = SplineMesh)
291
293 UFUNCTION(BlueprintCallable, Category = SplineMesh)
294 ENGINE_API void SetStartTangent(FVector StartTangent, bool bUpdateMesh = true);
295
297 UFUNCTION(BlueprintCallable, Category = SplineMesh)
299
301 UFUNCTION(BlueprintCallable, Category = SplineMesh)
302 ENGINE_API void SetEndPosition(FVector EndPos, bool bUpdateMesh = true);
303
305 UFUNCTION(BlueprintCallable, Category = SplineMesh)
307
309 UFUNCTION(BlueprintCallable, Category = SplineMesh)
310 ENGINE_API void SetEndTangent(FVector EndTangent, bool bUpdateMesh = true);
311
313 UFUNCTION(BlueprintCallable, Category = SplineMesh)
314 ENGINE_API void SetStartAndEnd(FVector StartPos, FVector StartTangent, FVector EndPos, FVector EndTangent, bool bUpdateMesh = true);
315
317 UFUNCTION(BlueprintCallable, Category = SplineMesh)
319
321 UFUNCTION(BlueprintCallable, Category = SplineMesh)
322 ENGINE_API void SetStartScale(FVector2D StartScale = FVector2D(1,1), bool bUpdateMesh = true);
323
325 UFUNCTION(BlueprintCallable, Category = SplineMesh)
326 ENGINE_API float GetStartRoll() const;
327
329 UFUNCTION(BlueprintCallable, Category = SplineMesh, meta = (DisplayName = "Set Start Roll Radians"))
330 ENGINE_API void SetStartRoll(float StartRoll, bool bUpdateMesh = true);
331
333 UFUNCTION(BlueprintCallable, Category = SplineMesh)
335
337 UFUNCTION(BlueprintCallable, Category = SplineMesh)
338 ENGINE_API FVector2D GetStartOffset() const;
339
341 UFUNCTION(BlueprintCallable, Category = SplineMesh)
342 ENGINE_API void SetStartOffset(FVector2D StartOffset, bool bUpdateMesh = true);
343
345 UFUNCTION(BlueprintCallable, Category = SplineMesh)
347
349 UFUNCTION(BlueprintCallable, Category = SplineMesh)
350 ENGINE_API void SetEndScale(FVector2D EndScale = FVector2D(1,1), bool bUpdateMesh = true);
351
353 UFUNCTION(BlueprintCallable, Category = SplineMesh)
354 ENGINE_API float GetEndRoll() const;
355
357 UFUNCTION(BlueprintCallable, Category = SplineMesh, meta = (DisplayName = "Set End Roll Radians"))
358 ENGINE_API void SetEndRoll(float EndRoll, bool bUpdateMesh = true);
359
361 UFUNCTION(BlueprintCallable, Category = SplineMesh)
363
365 UFUNCTION(BlueprintCallable, Category = SplineMesh)
366 ENGINE_API FVector2D GetEndOffset() const;
367
369 UFUNCTION(BlueprintCallable, Category = SplineMesh)
370 ENGINE_API void SetEndOffset(FVector2D EndOffset, bool bUpdateMesh = true);
371
373 UFUNCTION(BlueprintCallable, Category = SplineMesh)
374 ENGINE_API ESplineMeshAxis::Type GetForwardAxis() const;
375
377 UFUNCTION(BlueprintCallable, Category = SplineMesh)
378 ENGINE_API void SetForwardAxis(ESplineMeshAxis::Type InForwardAxis, bool bUpdateMesh = true);
379
381 UFUNCTION(BlueprintCallable, Category = SplineMesh)
383
385 UFUNCTION(BlueprintCallable, Category = SplineMesh)
387
389 UFUNCTION(BlueprintCallable, Category = SplineMesh)
390 ENGINE_API float GetBoundaryMin() const;
391
393 UFUNCTION(BlueprintCallable, Category = SplineMesh)
395
397 UFUNCTION(BlueprintCallable, Category = SplineMesh)
398 ENGINE_API float GetBoundaryMax() const;
399
401 UFUNCTION(BlueprintCallable, Category = SplineMesh)
403
406
408 bool GetbNeverNeedsCookedCollisionData() const { return bNeverNeedsCookedCollisionData; }
409
410 // Destroys the body setup, used to clear collision if the mesh goes missing
412 // Builds collision for the spline mesh (if collision is enabled)
413 ENGINE_API void RecreateCollision();
414
418 ENGINE_API FTransform CalcSliceTransform(const float DistanceAlong) const;
419
424 ENGINE_API FTransform CalcSliceTransformAtSplineOffset(const float Alpha, const float MinT=0.f, const float MaxT=1.0f) const;
425
428
429 inline static const double& GetAxisValueRef(const FVector3d& InVector, ESplineMeshAxis::Type InAxis);
430 inline static double& GetAxisValueRef(FVector3d& InVector, ESplineMeshAxis::Type InAxis);
431
432 inline static const float& GetAxisValueRef(const FVector3f& InVector, ESplineMeshAxis::Type InAxis);
433 inline static float& GetAxisValueRef(FVector3f& InVector, ESplineMeshAxis::Type InAxis);
434
438
439 ENGINE_API virtual float GetTextureStreamingTransformScale() const override;
440
441 ENGINE_API virtual void CollectPSOPrecacheData(const FPSOPrecacheParams& BasePrecachePSOParams, FMaterialInterfacePSOPrecacheParamsList& OutParams) override;
442
443private:
445};
446
448USTRUCT()
450{
452public:
454 explicit FSplineMeshInstanceData(const USplineMeshComponent* SourceComponent);
455
456 virtual ~FSplineMeshInstanceData() override = default;
457
458 virtual bool ContainsData() const override
459 {
460 return true;
461 }
462
464 {
465 Super::ApplyToComponent(Component, CacheApplyPhase);
466 CastChecked<USplineMeshComponent>(Component)->ApplyComponentInstanceData(this);
467 }
468
469 UPROPERTY()
470 FVector StartPos = FVector::ZeroVector;
471
472 UPROPERTY()
473 FVector EndPos = FVector::ZeroVector;
474
475 UPROPERTY()
476 FVector StartTangent = FVector::ZeroVector;
477
478 UPROPERTY()
479 FVector EndTangent = FVector::ZeroVector;
480};
481
482const double& USplineMeshComponent::GetAxisValueRef(const FVector3d& InVector, ESplineMeshAxis::Type InAxis)
483{
484 switch (InAxis)
485 {
487 return InVector.X;
489 return InVector.Y;
491 return InVector.Z;
492 default:
493 check(0);
494 return InVector.Z;
495 }
496}
497
498double& USplineMeshComponent::GetAxisValueRef(FVector3d& InVector, ESplineMeshAxis::Type InAxis)
499{
500 switch (InAxis)
501 {
503 return InVector.X;
505 return InVector.Y;
507 return InVector.Z;
508 default:
509 check(0);
510 return InVector.Z;
511 }
512}
513
514
515const float& USplineMeshComponent::GetAxisValueRef(const FVector3f& InVector, ESplineMeshAxis::Type InAxis)
516{
517 switch (InAxis)
518 {
520 return InVector.X;
522 return InVector.Y;
524 return InVector.Z;
525 default:
526 check(0);
527 return InVector.Z;
528 }
529}
530
531float& USplineMeshComponent::GetAxisValueRef(FVector3f& InVector, ESplineMeshAxis::Type InAxis)
532{
533 switch (InAxis)
534 {
536 return InVector.X;
538 return InVector.Y;
540 return InVector.Z;
541 default:
542 check(0);
543 return InVector.Z;
544 }
545}
546
547FVector USplineMeshComponent::GetAxisMask(ESplineMeshAxis::Type InAxis)
548{
549 switch (InAxis)
550 {
552 return FVector(0, 1, 1);
554 return FVector(1, 0, 1);
556 return FVector(1, 1, 0);
557 default:
558 check(0);
559 return FVector::ZeroVector;
560 }
561}
#define check(expr)
Definition AssertionMacros.h:314
ECacheApplyPhase
Definition ComponentInstanceDataCache.h:18
@ ForceInit
Definition CoreMiscDefines.h:155
FPlatformTypes::int32 int32
A 32-bit signed integer.
Definition Platform.h:1125
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
return true
Definition ExternalRpcRegistry.cpp:601
#define X(Name, Desc)
Definition FormatStringSan.h:47
#define FVector
Definition IOSSystemIncludes.h:8
UE::Math::TVector2< double > FVector2D
Definition MathFwd.h:48
#define UPROPERTY(...)
UObject definition macros.
Definition ObjectMacros.h:744
#define GENERATED_BODY(...)
Definition ObjectMacros.h:765
#define UFUNCTION(...)
Definition ObjectMacros.h:745
#define GENERATED_UCLASS_BODY(...)
Definition ObjectMacros.h:768
#define UCLASS(...)
Definition ObjectMacros.h:776
#define UENUM(...)
Definition ObjectMacros.h:749
#define USTRUCT(...)
Definition ObjectMacros.h:746
#define GENERATED_USTRUCT_BODY(...)
Definition ObjectMacros.h:767
ERelativeTransformSpace
Definition SceneComponent.h:43
@ RTS_World
Definition SceneComponent.h:45
ENGINE_API void PackSplineMeshParams(const FSplineMeshShaderParams &Params, const TArrayView< FVector4f > &Output)
Definition SplineMeshComponent.cpp:72
uint8_t uint8
Definition binka_ue_file_header.h:8
Definition Archive.h:1208
Definition ColorVertexBuffer.h:16
Definition NameTypes.h:617
Definition PrimitiveSceneProxy.h:296
Definition StaticMeshLight.h:24
Definition Interface_CollisionDataProvider.h:23
Definition ArrayView.h:139
Definition Array.h:670
Definition EnumAsByte.h:22
Definition StructOnScope.h:142
Definition ActorComponent.h:152
Definition BodySetup.h:128
Definition SplineMeshComponent.h:25
Type
Definition SplineMeshComponent.h:27
@ Z
Definition SplineMeshComponent.h:30
@ Y
Definition SplineMeshComponent.h:29
@ X
Definition SplineMeshComponent.h:28
Definition SplineMeshSceneResources.cpp:56
ENGINE_API FBox CalcBounds(const FVector &P0, const FVector &P1, const FVector &P2, const FVector &P3)
Definition BezierUtilities.cpp:26
Definition SplineMeshComponent.h:35
ENGINE_API float RealToFloatChecked(const double Value)
Definition SplineMeshComponent.cpp:41
Definition Guid.h:109
Definition MeshDescription.h:94
Definition NavigationSystemHelpers.h:25
Definition PSOPrecache.h:30
Definition UnrealType.h:6865
Definition SplineMeshComponent.h:450
FSplineMeshInstanceData()=default
virtual void ApplyToComponent(UActorComponent *Component, const ECacheApplyPhase CacheApplyPhase) override
Definition SplineMeshComponent.h:463
virtual bool ContainsData() const override
Definition SplineMeshComponent.h:458
virtual ~FSplineMeshInstanceData() override=default
Definition SplineMeshComponent.h:45
Definition StaticMeshComponent.h:958
Definition Interface_CollisionDataProviderCore.h:68
Definition Interface_CollisionDataProviderCore.h:28
Definition NaniteSceneProxy.h:66
Definition ObjectPtr.h:488
Definition BoxSphereBounds.h:25
T Z
Definition Vector.h:68
T Y
Definition Vector.h:65
static CORE_API const TVector< double > ZeroVector
Definition Vector.h:79
T X
Definition Vector.h:62