UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
CurveTable.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"
8#include "UObject/Object.h"
9#include "UObject/Class.h"
12#include "Curves/SimpleCurve.h"
13#include "CurveTable.generated.h"
14
16
17
18// forward declare JSON writer
19template <class CharType>
21template <class CharType, class PrintPolicy>
22class TJsonWriter;
23
27UENUM()
34
35
39UCLASS(MinimalAPI, Meta = (LoadBehavior = "LazyOnDemand"))
43{
45
47
48 const TMap<FName, FRealCurve*>& GetRowMap() const { return RowMap; }
49 const TMap<FName, FRealCurve*>& GetRowMap() { return RowMap; }
50
51 const TMap<FName, FRichCurve*>& GetRichCurveRowMap() const { check(CurveTableMode != ECurveTableMode::SimpleCurves); return *reinterpret_cast<const TMap<FName, FRichCurve*>*>(&RowMap); }
52 const TMap<FName, FRichCurve*>& GetRichCurveRowMap() { check(CurveTableMode != ECurveTableMode::SimpleCurves); return *reinterpret_cast<TMap<FName, FRichCurve*>*>(&RowMap); }
53
54 const TMap<FName, FSimpleCurve*>& GetSimpleCurveRowMap() const { check(CurveTableMode != ECurveTableMode::RichCurves); return *reinterpret_cast<const TMap<FName, FSimpleCurve*>*>(&RowMap); }
55 const TMap<FName, FSimpleCurve*>& GetSimpleCurveRowMap() { check(CurveTableMode != ECurveTableMode::RichCurves); return *reinterpret_cast<TMap<FName, FSimpleCurve*>*>(&RowMap); }
56
57 ECurveTableMode GetCurveTableMode() const { return CurveTableMode; }
58
60 ENGINE_API virtual void RemoveRow(FName RowName);
61 ENGINE_API FRichCurve& AddRichCurve(FName RowName);
62 ENGINE_API FSimpleCurve& AddSimpleCurve(FName RowName);
63
65 ENGINE_API void RenameRow(FName& CurveName, FName& NewCurveName);
66
68 ENGINE_API void DeleteRow(FName& CurveName);
69
70protected:
77
78 static FTransactionallySafeCriticalSection& GetCurveTableChangeCriticalSection();
79
80public:
81 //~ Begin UObject Interface.
82 virtual void FinishDestroy() override;
83 virtual void Serialize( FArchive& Ar ) override;
84
85#if WITH_EDITORONLY_DATA
86 virtual void GetAssetRegistryTags(FAssetRegistryTagsContext Context) const override;
87 UE_DEPRECATED(5.4, "Implement the version that takes FAssetRegistryTagsContext instead.")
88 virtual void GetAssetRegistryTags(TArray<FAssetRegistryTag>& OutTags) const override;
89 virtual void PostInitProperties() override;
91
92 UPROPERTY(VisibleAnywhere, Instanced, Category=ImportSettings)
94
96 UPROPERTY()
98
99#endif // WITH_EDITORONLY_DATA
100
101 //~ End UObject Interface
102
103 //~ Begin FCurveOwnerInterface Interface.
104 UE_DEPRECATED(5.6, "Use version taking a TAdderReserverRef")
106 virtual void GetCurves(TAdderReserverRef<FRichCurveEditInfoConst> Curves) const override;
108 virtual void ModifyOwner() override;
109 virtual void MakeTransactional() override;
111 virtual bool IsValidCurve(FRichCurveEditInfo CurveInfo) override;
112 virtual TArray<const UObject*> GetOwners() const override;
114 {
115 return RepointCurveOwnerAsset(InPackageReloadedEvent, this, OutNewCurveOwner);
116 }
117 virtual bool HasRichCurves() const override
118 {
119 return CurveTableMode != ECurveTableMode::SimpleCurves;
120 }
121 //~ End FCurveOwnerInterface Interface.
122
124 FOnCurveTableChanged& OnCurveTableChanged() { return OnCurveTableChangedDelegate; }
125
126 //~ Begin UCurveTable Interface
127
129 FRealCurve* FindCurve(FName RowName, const FString& ContextString, bool bWarnIfNotFound = true) const
130 {
131 if (RowName.IsNone())
132 {
133 UE_CLOG(bWarnIfNotFound, LogCurveTable, Warning, TEXT("UCurveTable::FindCurve : NAME_None is invalid row name for CurveTable '%s' (%s)."), *GetPathName(), *ContextString);
134 return nullptr;
135 }
136
137 FRealCurve* const* FoundCurve = RowMap.Find(RowName);
138
139 if (FoundCurve == nullptr)
140 {
141 UE_CLOG(bWarnIfNotFound, LogCurveTable, Warning, TEXT("UCurveTable::FindCurve : Row '%s' not found in CurveTable '%s' (%s)."), *RowName.ToString(), *GetPathName(), *ContextString);
142 return nullptr;
143 }
144
145 return *FoundCurve;
146 }
147
148 FRichCurve* FindRichCurve(FName RowName, const FString& ContextString, bool bWarnIfNotFound = true) const
149 {
150 if (CurveTableMode == ECurveTableMode::SimpleCurves)
151 {
152 UE_LOG(LogCurveTable, Error, TEXT("UCurveTable::FindCurve : Using FindRichCurve on CurveTable '%s' (%s) that is storing simple curves."), *GetPathName(), *ContextString);
153 return nullptr;
154 }
155
156 return (FRichCurve*)FindCurve(RowName, ContextString, bWarnIfNotFound);
157 }
158
159 FSimpleCurve* FindSimpleCurve(FName RowName, const FString& ContextString, bool bWarnIfNotFound = true) const
160 {
161 if (CurveTableMode == ECurveTableMode::RichCurves)
162 {
163 UE_LOG(LogCurveTable, Error, TEXT("UCurveTable::FindCurve : Using FindSimpleCurve on CurveTable '%s' (%s) that is storing rich curves."), *GetPathName(), *ContextString);
164 return nullptr;
165 }
166
167 return (FSimpleCurve*)FindCurve(RowName, ContextString, bWarnIfNotFound);
168 }
169
172 {
173 // If RowName is none, it won't be found in the map
174 FRealCurve* const* FoundCurve = RowMap.Find(RowName);
175
176 if (FoundCurve == nullptr)
177 {
178 return nullptr;
179 }
180
181 return *FoundCurve;
182 }
183
185 ENGINE_API FString GetTableAsString() const;
186
188 ENGINE_API FString GetTableAsCSV() const;
189
191 ENGINE_API FString GetTableAsJSON() const;
192
194 template <typename CharType = TCHAR>
195 bool WriteTableAsJSON(const TSharedRef< TJsonWriter<CharType, TPrettyJsonPrintPolicy<CharType> > >& JsonWriter,bool bAsArray = true) const;
196
204 ENGINE_API TArray<FString> CreateTableFromCSVString(const FString& InString, ERichCurveInterpMode InterpMode = RCIM_Linear);
205
213 ENGINE_API TArray<FString> CreateTableFromJSONString(const FString& InString, ERichCurveInterpMode InterpMode = RCIM_Linear);
214
219 ENGINE_API TArray<FString> CreateTableFromOtherTable(const UCurveTable* InTable);
220
222 ENGINE_API virtual void EmptyTable();
223
224 ENGINE_API static void InvalidateAllCachedCurves();
225
227 {
228 return GlobalCachedCurveID;
229 }
230
231#if WITH_EDITOR
232 virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
233#endif // WITH_EDITOR
234
235protected:
236
241 static FName MakeValidName(const FString& InString);
242
244
245
246private:
247
249 FOnCurveTableChanged OnCurveTableChangedDelegate;
250
251protected:
253};
254
255
259USTRUCT(BlueprintType)
261{
263
265 : CurveTable(nullptr)
266 , RowName(NAME_None)
267 { }
268
270 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=CurveTableRowHandle, meta=(DisplayThumbnail="false"))
271 TObjectPtr<const class UCurveTable> CurveTable;
272
274 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=CurveTableRowHandle)
275 FName RowName;
276
278 bool IsValid(const FString& ContextString) const
279 {
280 return (GetCurve(ContextString, false) != nullptr);
281 }
282
284 bool IsNull() const
285 {
286 return CurveTable == nullptr && RowName.IsNone();
287 }
288
290 ENGINE_API FRealCurve* GetCurve(const FString& ContextString, bool bWarnIfNotFound=true) const;
291
293 ENGINE_API FRichCurve* GetRichCurve(const FString& ContextString, bool bWarnIfNotFound=true) const;
294
296 ENGINE_API FSimpleCurve* GetSimpleCurve(const FString& ContextString, bool bWarnIfNotFound = true) const;
297
303 float Eval(float XValue,const FString& ContextString) const
304 {
305 float Result = 0.f;
306 Eval(XValue, &Result, ContextString);
307 return Result;
308 }
309
316 ENGINE_API bool Eval(float XValue, float* YValue,const FString& ContextString) const;
317
318 ENGINE_API bool operator==(const FCurveTableRowHandle& Other) const;
320 ENGINE_API void PostSerialize(const FArchive& Ar);
321
324 {
325 return HashCombine(GetTypeHash(Handle.RowName), PointerHash(Handle.CurveTable));
326 }
327};
328
329template<>
331{
332 enum
333 {
335 };
336};
337
339#define GETCURVE_REPORTERROR(Handle) Handle.GetCurve(FString::Printf(TEXT("%s.%s"), *GetPathName(), TEXT(#Handle)))
340
342#define GETCURVE_REPORTERROR_WITHPATHNAME(Handle, PathNameString) Handle.GetCurve(FString::Printf(TEXT("%s.%s"), *PathNameString, TEXT(#Handle)))
#define check(expr)
Definition AssertionMacros.h:314
#define UE_DEPRECATED(Version, Message)
Definition CoreMiscDefines.h:302
#define TEXT(x)
Definition Platform.h:1272
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
ECurveTableMode
Definition CurveTable.h:29
#define DECLARE_MULTICAST_DELEGATE(DelegateName)
Definition DelegateCombinations.h:23
UE_FORCEINLINE_HINT bool operator!=(const FIndexedPointer &Other) const
Definition LockFreeList.h:76
#define DECLARE_LOG_CATEGORY_EXTERN(CategoryName, DefaultVerbosity, CompileTimeVerbosity)
Definition LogMacros.h:361
#define UE_CLOG(Condition, CategoryName, Verbosity, Format,...)
Definition LogMacros.h:298
#define UE_LOG(CategoryName, Verbosity, Format,...)
Definition LogMacros.h:270
#define UPROPERTY(...)
UObject definition macros.
Definition ObjectMacros.h:744
#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
ERichCurveInterpMode
Definition RealCurve.h:13
::FCriticalSection FTransactionallySafeCriticalSection
Definition TransactionallySafeCriticalSection.h:16
uint32 PointerHash(const void *Key)
Definition TypeHash.h:91
constexpr uint32 HashCombine(uint32 A, uint32 C)
Definition TypeHash.h:36
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition Archive.h:1208
Definition AssetRegistryTagsContext.h:98
Definition CurveOwnerInterface.h:14
Definition NameTypes.h:617
CORE_API FString ToString() const
Definition UnrealNames.cpp:3537
FORCEINLINE bool IsNone() const
Definition NameTypes.h:827
Definition PackageReload.h:67
Definition Array.h:670
Definition JsonWriter.h:85
Definition UnrealString.h.inl:34
Definition SharedPointer.h:153
Definition AssetImportData.h:72
Definition CurveTable.h:43
FRealCurve * FindCurveUnchecked(FName RowName) const
Definition CurveTable.h:171
static int32 GetGlobalCachedCurveID()
Definition CurveTable.h:226
virtual bool HasRichCurves() const override
Definition CurveTable.h:117
ECurveTableMode CurveTableMode
Definition CurveTable.h:252
FRichCurve * FindRichCurve(FName RowName, const FString &ContextString, bool bWarnIfNotFound=true) const
Definition CurveTable.h:148
FSimpleCurve * FindSimpleCurve(FName RowName, const FString &ContextString, bool bWarnIfNotFound=true) const
Definition CurveTable.h:159
FOnCurveTableChanged & OnCurveTableChanged()
Definition CurveTable.h:124
FRealCurve * FindCurve(FName RowName, const FString &ContextString, bool bWarnIfNotFound=true) const
Definition CurveTable.h:129
static ENGINE_API int32 GlobalCachedCurveID
Definition CurveTable.h:243
TMap< FName, FRealCurve * > RowMap
Definition CurveTable.h:76
Definition Object.h:95
Definition CurveTable.h:261
friend uint32 GetTypeHash(const FCurveTableRowHandle &Handle)
Definition CurveTable.h:323
float Eval(float XValue, const FString &ContextString) const
Definition CurveTable.h:303
bool IsNull() const
Definition CurveTable.h:284
Definition UnrealType.h:6865
Definition RealCurve.h:125
Definition RichCurve.h:470
Definition RichCurve.h:200
Definition SimpleCurve.h:71
Definition AdderRef.h:147
Definition ObjectPtr.h:488
Definition PrettyJsonPrintPolicy.h:16
Definition StructOpsTypeTraits.h:11
@ WithPostSerialize
Definition StructOpsTypeTraits.h:25
Definition StructOpsTypeTraits.h:46
Definition Object.h:827