UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
MovieSceneNumericVariant.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
3#pragma once
4
5#include "CoreTypes.h"
6#include "MovieSceneNumericVariant.generated.h"
7
9
10#ifndef UE_MOVIESCENE_WEAKNUMERICVARIANT_CHECKS
11 #define UE_MOVIESCENE_WEAKNUMERICVARIANT_CHECKS DO_CHECK
12#endif
13
14
33USTRUCT(BlueprintType)
35{
36 static_assert(PLATFORM_LITTLE_ENDIAN, "This class does not currently support big-endian platforms");
37
39
40
46
47
52
53
58
59
64
65
71
72
76 MOVIESCENE_API friend bool operator==(const FMovieSceneNumericVariant& A, const FMovieSceneNumericVariant& B);
77
78
83
84
85public:
86
93
94
101
102
110
111
116 MOVIESCENE_API void MakeWeakUnsafe();
117
118
124 MOVIESCENE_API double Get() const;
125
126
132
133
137 bool IsLiteral() const;
138
139
143 double GetLiteral() const;
144
145
149 float GetLiteralAsFloat() const;
150
151
155 bool IsCustomPtr() const;
156
157
158public:
159
160
165 MOVIESCENE_API FMovieSceneNumericVariant ShallowCopy() const;
166
167
172
173
174public:
175
176
178 bool Serialize(FArchive& Ar);
179 bool Identical(const FMovieSceneNumericVariant* Other, uint32 PortFlags) const;
180 void AddStructReferencedObjects(FReferenceCollector& Collector);
181 bool SerializeFromMismatchedTag(const FPropertyTag& Tag, FStructuredArchive::FSlot Slot);
182 bool ExportTextItem(FString& ValueStr, const FMovieSceneNumericVariant& DefaultValue, UObject* Parent, int32 PortFlags, UObject* ExportRootScope) const;
183 bool ImportTextItem(const TCHAR*& Buffer, int32 PortFlags, UObject* Parent, FOutputDevice* ErrorText, FArchive* InSerializingArchive = nullptr);
185
186 bool SerializeCustom(FArchive& Ar, TFunctionRef<void(FArchive&, uint8&, void*)>);
187
188
189public:
190
191
201 template<typename T>
202 void SetTypedData(const T& InValue, uint8 InType);
203
204
209 template<typename T>
210 T UnsafePayloadCast() const;
211
212
219 MOVIESCENE_API void SetTypeBits(uint8 InType);
220
221
226 MOVIESCENE_API uint8 GetTypeBits() const;
227
228
229private:
230
231 // Flags specifying different regions on an IEEE 754 double
232 static constexpr uint64 HIGH_Bits = 0xFFF0000000000000u; // All high bits (eg, Sign + exponent bits)
233 static constexpr uint64 EXP_Bits = 0x7FF0000000000000u; // Exponent bits
234 static constexpr uint64 SIGN_Bit = 0x8000000000000000u; // Sign bit
235 static constexpr uint64 QUIET_Bit = 0x0008000000000000u; // Quiet NaN bit
236 static constexpr uint64 TYPE_Bits = 0x0007000000000000u; // Unused NaN bits that we repurpose for variant type information
237 static constexpr uint64 TYPE_CustomPtr = 0x0000000000000000u; // INTENTIONALLY ZERO: Special value for TYPE_Bits when our data points to a UMovieSceneNumericVariantGetter*.
238 static constexpr uint64 PAYLOAD_Bits = 0x0000FFFFFFFFFFFFu; // Bitmask specifying valid bits that can be used for custom payloads when any of TAGGED_Bits is set
239
240 static constexpr uint64 CUSTOMPTR_FlagBits = 0x0000000000000003u; // Low bitmask that (ab)uses the alignment of UMovieSceneNumericVariantGetter to encode additional flags
241 static constexpr uint64 CUSTOMPTR_Weak = 0x0000000000000001u; // Low bit that signifies the wrapped custom pointer should not be reported to the reference graph.
242
243 static constexpr uint64 TAGGED_Bits = SIGN_Bit | EXP_Bits | QUIET_Bit;
244
245
246 double& GetLiteralRef()
247 {
248 checkSlow(IsLiteral());
249 return *reinterpret_cast<double*>(Data);
250 }
251
252
257 bool HasCustomWeakPtrFlag() const;
258
259public:
260
264
265private:
266
267 alignas(8) uint8 Data[8];
268
269#if UE_MOVIESCENE_WEAKNUMERICVARIANT_CHECKS
271#endif
272};
273
274template<>
289
290
292{
293 const uint64 Value = *reinterpret_cast<const uint64*>(Data);
294
295 // Literal if the double is a quiet nan
296 return (Value & TAGGED_Bits) != TAGGED_Bits;
297}
298
300{
302 return *reinterpret_cast<const double*>(Data);
303}
304
306{
307 return static_cast<float>(
308 FMath::Clamp<double>(
309 GetLiteral(),
310 std::numeric_limits<float>::lowest(),
311 std::numeric_limits<float>::max()
312 )
313 );
314}
315
317{
318 return !IsLiteral() && (GetTypeBits() == TYPE_CustomPtr);
319}
320
321
322template<typename T>
324{
325 check(InType > TYPE_CustomPtr && (InType <= TYPE_Bits >> 48) );
326 static_assert(sizeof(T) <= 6, "Type too big. Maximum supported size is 48 bits");
327
328 uint64 NewValue = 0;
329
330 void* NewValueAddr = &NewValue;
331 uint8* NewValueBytes = static_cast<uint8*>(NewValueAddr);
332
334
335 *reinterpret_cast<uint64*>(Data) = TAGGED_Bits | NewValue;
337}
338
339template<typename T>
341{
342 check(!IsLiteral());
343 const uint64 PtrValue = *reinterpret_cast<const uint64*>(Data) & PAYLOAD_Bits;
344 const void* ValuePtr = &PtrValue;
345 return *reinterpret_cast<const T*>(ValuePtr);
346}
#define PLATFORM_LITTLE_ENDIAN
Definition AndroidPlatform.h:38
#define checkSlow(expr)
Definition AssertionMacros.h:332
#define check(expr)
Definition AssertionMacros.h:314
ENoInit
Definition CoreMiscDefines.h:158
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
FPlatformTypes::uint64 uint64
A 64-bit unsigned integer.
Definition Platform.h:1117
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
UE_FORCEINLINE_HINT bool operator!=(const FIndexedPointer &Other) const
Definition LockFreeList.h:76
#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
Definition OutputDevice.h:133
Definition UObjectGlobals.h:2492
Definition StructuredArchiveSlots.h:52
Definition Array.h:670
Definition AssetRegistryState.h:50
Definition MovieSceneNumericVariantGetter.h:17
Definition Object.h:95
virtual COREUOBJECT_API void GetPreloadDependencies(TArray< UObject * > &OutDeps)
Definition Obj.cpp:1608
static UE_FORCEINLINE_HINT void * Memcpy(void *Dest, const void *Src, SIZE_T Count)
Definition UnrealMemory.h:160
Definition MovieSceneNumericVariant.h:35
FMovieSceneNumericVariant & operator=(FMovieSceneNumericVariant &&In)=default
MOVIESCENE_API uint8 GetTypeBits() const
Definition MovieSceneNumericVariant.cpp:186
void SetTypedData(const T &InValue, uint8 InType)
Definition MovieSceneNumericVariant.h:323
float GetLiteralAsFloat() const
Definition MovieSceneNumericVariant.h:305
FMovieSceneNumericVariant(FMovieSceneNumericVariant &&In)=default
bool IsLiteral() const
Definition MovieSceneNumericVariant.h:291
MOVIESCENE_API void SetTypeBits(uint8 InType)
Definition MovieSceneNumericVariant.cpp:174
double GetLiteral() const
Definition MovieSceneNumericVariant.h:299
FMovieSceneNumericVariant(const FMovieSceneNumericVariant &Other)=default
FMovieSceneNumericVariant & operator=(const FMovieSceneNumericVariant &Other)=default
bool IsCustomPtr() const
Definition MovieSceneNumericVariant.h:316
T UnsafePayloadCast() const
Definition MovieSceneNumericVariant.h:340
Definition PropertyTag.h:38
Definition StructOpsTypeTraits.h:11
@ WithStructuredSerializeFromMismatchedTag
Definition StructOpsTypeTraits.h:29
@ WithGetPreloadDependencies
Definition StructOpsTypeTraits.h:32
@ WithAddStructReferencedObjects
Definition StructOpsTypeTraits.h:22
@ WithIdenticalViaEquality
Definition StructOpsTypeTraits.h:18
@ WithCopy
Definition StructOpsTypeTraits.h:17
@ WithExportTextItem
Definition StructOpsTypeTraits.h:20
@ WithSerializer
Definition StructOpsTypeTraits.h:23
@ WithImportTextItem
Definition StructOpsTypeTraits.h:21
Definition StructOpsTypeTraits.h:46
Definition WeakObjectPtrTemplates.h:25