UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
Spline.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"
6#include "Math/InterpCurve.h"
8
9#include "Spline.generated.h"
10
11struct FSplinePoint;
12struct FSplineCurves;
13class FLegacySpline;
14class FNewSpline;
15
16struct UE_EXPERIMENTAL(5.7, "New spline APIs are experimental.") FSpline;
17
22USTRUCT()
24{
26
29 ENGINE_API FSpline& operator=(const FSpline& Other);
30 ENGINE_API FSpline& operator=(const FSplineCurves& Other);
32
33 /* Control Point Index Interface */
34
37 ENGINE_API void AddPoint(const FSplinePoint& InPoint);
39 ENGINE_API void InsertPoint(const FSplinePoint& InPoint, int32 Index);
40 ENGINE_API FSplinePoint GetPoint(const int32 Index) const;
41 ENGINE_API void RemovePoint(const int32 Index);
42
43 ENGINE_API void SetLocation(int32 Index, const FVector& InLocation);
44 ENGINE_API FVector GetLocation(const int32 Index) const;
45
46 ENGINE_API void SetInTangent(const int32 Index, const FVector& InTangent);
47 ENGINE_API FVector GetInTangent(const int32 Index) const;
48
49 ENGINE_API void SetOutTangent(const int32 Index, const FVector& OutTangent);
50 ENGINE_API FVector GetOutTangent(const int32 Index) const;
51
52 ENGINE_API void SetRotation(int32 Index, const FQuat& InRotation);
53 ENGINE_API FQuat GetRotation(const int32 Index) const;
54
55 ENGINE_API void SetScale(int32 Index, const FVector& InScale);
56 ENGINE_API FVector GetScale(const int32 Index) const;
57
58 ENGINE_API void SetSplinePointType(int32 Index, EInterpCurveMode Type);
59 ENGINE_API EInterpCurveMode GetSplinePointType(int32 Index) const;
60
61 ENGINE_API float GetParameterAtIndex(int32 Index) const;
62 ENGINE_API float GetParameterAtDistance(float Distance) const;
63 ENGINE_API float GetDistanceAtParameter(float Parameter) const;
64
65 ENGINE_API FQuat GetOrientation(int32 Index) const;
66 ENGINE_API void SetOrientation(int32 Index, const FQuat& InOrientation);
67
68 /* Parameter Interface */
69
70 ENGINE_API FVector Evaluate(float Param) const;
71 ENGINE_API FVector EvaluateDerivative(float Param) const;
72 ENGINE_API FQuat EvaluateRotation(float Param) const;
73 ENGINE_API FVector EvaluateScale(float Param) const;
74
75 ENGINE_API FQuat GetOrientation(float Param) const;
76
77 /* Attribute Interface */
78
79 // Non-Templated functions
80 bool SupportsAttributes() const { return IsNew(); }
81 ENGINE_API bool HasAttributeChannel(FName AttributeName) const;
82 ENGINE_API bool RemoveAttributeChannel(FName AttributeName) const;
83 ENGINE_API TArray<FName> GetFloatPropertyChannels() const;
84 ENGINE_API TArray<FName> GetVectorPropertyChannels() const;
85
86 template <typename AttrType> ENGINE_API float GetAttributeParameter(int32 Index, const FName& Name) const;
87 template <typename AttrType> ENGINE_API int32 SetAttributeParameter(int32 Index, float Parameter, const FName& Name);
88 template <typename AttrType> ENGINE_API int32 NumAttributeValues(FName AttributeName) const;
89 template <typename AttrType> ENGINE_API AttrType GetAttributeValue(int32 Index, const FName& Name) const;
90 template <typename AttrType> ENGINE_API void SetAttributeValue(int32 Index, const AttrType& Value, const FName& Name);
91 template <typename AttrType> ENGINE_API bool CreateAttributeChannel(FName AttributeName) const;
92 template <typename AttrType> ENGINE_API int32 AddAttributeValue(float Param, const AttrType& Value, FName AttributeName) const;
93 template <typename AttrType> ENGINE_API void RemoveAttributeValue(int32 Index, FName AttributeName);
94 template <typename AttrType> ENGINE_API AttrType EvaluateAttribute(float Param, FName AttributeName) const;
95
96 ENGINE_API float FindNearest(const FVector& InLocation, float& OutSquaredDist) const;
97 ENGINE_API float FindNearestOnSegment(const FVector& InLocation, int32 SegmentIndex, float& OutSquaredDist) const;
98
99 /* Misc Interface */
100
101 ENGINE_API bool operator==(const FSpline& Other) const;
102 bool operator!=(const FSpline& Other) const
103 {
104 return !(*this == Other);
105 }
106
108 {
109 Spline.Serialize(Ar);
110 return Ar;
111 }
112 ENGINE_API bool Serialize(FArchive& Ar);
113 ENGINE_API void SerializeLoad(FArchive& Ar);
114 ENGINE_API void SerializeSave(FArchive& Ar) const;
115 ENGINE_API bool ExportTextItem(FString& ValueStr, FSpline const& DefaultValue, class UObject* Parent, int32 PortFlags, class UObject* ExportRootScope) const;
116 ENGINE_API bool ImportTextItem(const TCHAR*& Buffer, int32 PortFlags, UObject* Parent, FOutputDevice* ErrorText);
117
118 uint32 GetVersion() const { return Version; }
119
120 ENGINE_API const FInterpCurveVector& GetSplinePointsPosition() const;
121 ENGINE_API const FInterpCurveQuat& GetSplinePointsRotation() const;
122 ENGINE_API const FInterpCurveVector& GetSplinePointsScale() const;
123
125 ENGINE_API float GetSegmentLength(const int32 Index, const float Param, const FVector& Scale3D = FVector(1.0f)) const;
126
128 ENGINE_API float GetSplineLength() const;
129
131 ENGINE_API int32 GetNumSegments() const;
132
134 ENGINE_API int32 GetNumControlPoints() const;
135
137 ENGINE_API void Reset();
138
140 ENGINE_API void ResetRotation();
141
143 ENGINE_API void ResetScale();
144
145 ENGINE_API void SetClosedLoop(bool bClosed);
146 ENGINE_API bool IsClosedLoop() const;
147
149 {
150 bool bClosedLoop = false;
151 bool bStationaryEndpoints = false;
152 int32 ReparamStepsPerSegment = 10;
153 bool bLoopPositionOverride = false;
154 float LoopPosition = 0.0f;
155 FVector Scale3D = FVector(1.0f);
156 };
157
159 ENGINE_API void UpdateSpline(const FUpdateSplineParams& InParams);
160
162 ENGINE_API void UpdateSpline();
163
165
166private:
167
168 static inline const FInterpCurveVector PositionCurve;
169 static inline const FInterpCurveQuat RotationCurve;
170 static inline const FInterpCurveVector ScaleCurve;
171
172 // Used for upgrade logic in spline component.
173 // Not ideal, but allows us to automatically populate the proxy
174 // at serialize time when we might otherwise not be able to.
175 friend class USplineComponent;
176 friend struct FPCGSplineStruct;
177
178#if WITH_EDITOR
180#endif
181 uint8 CurrentImplementation;
182
183 uint32 Version;
184
185 FUpdateSplineParams CachedUpdateSplineParams;
186
187 // probably better implemented as a TSharedPtr<ISplineInterface> or something
188 struct { // Invalid when CurrentImplementation is 0 or 3.
189 TSharedPtr<FLegacySpline> LegacyData; // Valid when CurrentImplementation is 1.
190 TSharedPtr<FNewSpline> NewData; // Valid when CurrentImplementation is 2.
191 };
192
193 bool IsEnabled() const { return CurrentImplementation != 0; }
194 bool IsLegacy() const { return CurrentImplementation == 1; }
195 bool IsNew() const { return CurrentImplementation == 2; }
196
197#if WITH_EDITOR
198 bool WasEnabled() const { return PreviousImplementation != 0; }
199 bool WasLegacy() const { return PreviousImplementation == 1; }
200 bool WasNew() const { return PreviousImplementation == 2; }
201
205#endif
206
207public:
208
209 // True if a given FSpline will actually be implemented when instantiated.
210 static bool IsEnabledStatic();
211};
212
213template<>
215{
216 enum
217 {
218 WithSerializer = true, // Enables the use of a custom Serialize method.
219 WithIdenticalViaEquality = true, // Enables the use of a custom equality operator.
220 WithExportTextItem = true, // Enables the use of a custom ExportTextItem method.
221 WithImportTextItem = true, // Enables the use of a custom ImportTextItem method.
222 };
223};
#define UE_EXPERIMENTAL(Version, Message)
Definition CoreMiscDefines.h:369
FPlatformTypes::TCHAR TCHAR
Either ANSICHAR or WIDECHAR, depending on whether the platform supports wide characters or the requir...
Definition Platform.h:1135
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
#define FVector
Definition IOSSystemIncludes.h:8
EInterpCurveMode
Definition InterpCurvePoint.h:16
#define GENERATED_BODY(...)
Definition ObjectMacros.h:765
#define USTRUCT(...)
Definition ObjectMacros.h:746
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Archive.h:1208
virtual void Serialize(void *V, int64 Length)
Definition Archive.h:1689
Definition IDelegateInstance.h:14
Definition Spline.cpp:742
Definition NameTypes.h:617
Definition Spline.cpp:175
Definition OutputDevice.h:133
Definition Array.h:670
Definition SharedPointer.h:692
Definition Object.h:95
U16 Index
Definition radfft.cpp:71
Definition SplineComponent.h:76
Definition SplineComponent.h:166
Definition Spline.h:149
Definition Spline.h:24
uint32 GetVersion() const
Definition Spline.h:118
TSharedPtr< FNewSpline > NewData
Definition Spline.h:190
ENGINE_API int32 SetAttributeParameter(int32 Index, float Parameter, const FName &Name)
ENGINE_API AttrType GetAttributeValue(int32 Index, const FName &Name) const
bool SupportsAttributes() const
Definition Spline.h:80
ENGINE_API float GetAttributeParameter(int32 Index, const FName &Name) const
ENGINE_API void SetAttributeValue(int32 Index, const AttrType &Value, const FName &Name)
ENGINE_API void RemoveAttributeValue(int32 Index, FName AttributeName)
TSharedPtr< FLegacySpline > LegacyData
Definition Spline.h:189
ENGINE_API int32 NumAttributeValues(FName AttributeName) const
ENGINE_API AttrType EvaluateAttribute(float Param, FName AttributeName) const
friend FArchive & operator<<(FArchive &Ar, FSpline &Spline)
Definition Spline.h:107
ENGINE_API int32 AddAttributeValue(float Param, const AttrType &Value, FName AttributeName) const
ENGINE_API bool CreateAttributeChannel(FName AttributeName) const
bool operator!=(const FSpline &Other) const
Definition Spline.h:102
Definition StructOpsTypeTraits.h:11
@ WithIdenticalViaEquality
Definition StructOpsTypeTraits.h:18
@ WithExportTextItem
Definition StructOpsTypeTraits.h:20
@ WithSerializer
Definition StructOpsTypeTraits.h:23
@ WithImportTextItem
Definition StructOpsTypeTraits.h:21
Definition StructOpsTypeTraits.h:46