UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
TrackInstancePropertyBindings.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
7#include "Containers/Map.h"
8#include "Misc/TVariant.h"
9#include "UObject/Class.h"
10#include "UObject/ObjectKey.h"
11#include "UObject/UnrealType.h"
13
14namespace UE::MovieScene
15{
16
17struct FSourcePropertyValue;
18
23{
25
26 void* ContainerAddress = nullptr;
27
29
31 {
34 {
35 return PropertyPtr;
36 }
37 return nullptr;
38 }
39
40 template<typename ValueType>
41 ValueType* GetPropertyAddress() const
42 {
44 {
46 {
47 return PropertyPtr->ContainerPtrToValuePtr<ValueType>(ContainerAddress);
48 }
50 {
51 FScriptArrayHelper ArrayHelper(ArrayProp, ArrayProp->ContainerPtrToValuePtr<void>(ContainerAddress));
52 check(ArrayHelper.IsValidIndex(ArrayIndex));
53 return (ValueType*)ArrayHelper.GetRawPtr(ArrayIndex);
54 }
55 }
56 return nullptr;
57 }
58};
59
64{
65private:
66
67 using FData = TVariant<
68 // ContainerOffset : A fixed offset to jump by.
69 // Size = 4 bytes
70 uint32,
71 // CheckArrayIndex : A jump into an array's buffer, checking that the element index we'll
72 // offset to next is still valid.
73 // Size = 4 bytes
74 int32,
75 // CheckStruct : A jump into an instanced struct's buffer, checking that the struct type
76 // is what we expect.
77 // Size = 8 bytes
79 >;
80 FData Data;
81
82public:
83
84 void* ResolveAddress(void* ContainerAddress, bool& bNeedsRecaching) const;
85
86 void SetContainerOffset(uint32 InOffset) { Data.Set<uint32>(InOffset); }
89};
90// The TVariant data type flag is 8 bytes so with the biggest union field being 8 bytes, it should
91// all fit inside of 16 bytes.
92static_assert(sizeof(FVolatilePropertyStep) <= 16, "Try to fit FVolatilePropertyStep inside 16 bytes");
93
100{
101 const UObject* RootContainer = nullptr;
103
107
109 {
112 {
113 return PropertyPtr;
114 }
115 return nullptr;
116 }
117
119 {
120 return ResolvePropertySteps(true);
121 }
122
123 template<typename ValueType>
124 ValueType* GetPropertyAddress() const
125 {
126 return (ValueType*)ResolvePropertySteps(false);
127 }
128
129private:
130
131 MOVIESCENE_API void* ResolvePropertySteps(bool bStopAtLeafStep) const;
132
133 void* ResolvePropertyStepsImpl(bool bStopAtLeafStep, bool& bNeedsRecaching) const;
134};
135
136} // namespace UE::MovieScene
137
143{
144public:
145
147
154 template <typename ValueType>
156 {
157 const FResolvedPropertyAndFunction& PropAndFunction = FindOrAdd(InRuntimeObject);
158
159 FProperty* Property = PropAndFunction.GetValidProperty();
160 if (Property && Property->HasSetter())
161 {
162 Property->CallSetter(&InRuntimeObject, &PropertyValue);
163 }
164 else if (UFunction* SetterFunction = PropAndFunction.SetterFunction.Get())
165 {
166 InvokeSetterFunction(&InRuntimeObject, SetterFunction, PropertyValue);
167 }
168 else if (ValueType* Val = PropAndFunction.GetPropertyAddress<ValueType>())
169 {
170 *Val = MoveTempIfPossible(PropertyValue);
171 }
172 }
173
181
188
196
204
212
219 template <typename ValueType>
221 {
222 ValueType Value{};
223
224 const FResolvedPropertyAndFunction& PropAndFunction = FindOrAdd(Object);
226
227 return Value;
228 }
229
236 template <typename ValueType>
238 {
239 ValueType Value{};
240
241 const FResolvedPropertyAndFunction& PropAndFunction = FindOrAdd(Object);
243 {
244 return Value;
245 }
246
247 return TOptional<ValueType>();
248 }
249
257
264 template <typename ValueType>
266 {
267 const FResolvedPropertyAndFunction& PropAndFunction = FindOrAdd(Object);
268
269 if (ValueType* Val = PropAndFunction.GetPropertyAddress<ValueType>())
270 {
271 *Val = InValue;
272 }
273 }
274
276 const FString& GetPropertyPath() const
277 {
278 return PropertyPath;
279 }
280
282 const FName& GetPropertyName() const
283 {
284 return PropertyName;
285 }
286
287public:
288
298
306 template <typename ValueType>
308 {
309 checkf(Object, TEXT("No object specified"));
310
311 FResolvedPropertyAndFunction PropAndFunction = FindPropertyAndFunction(Object, InPropertyPath);
312
313 ValueType Value;
315 {
316 return Value;
317 }
318
319 return TOptional<ValueType>();
320 }
321
324
325private:
326
332 template<typename T>
333 static void InvokeSetterFunction(UObject* InRuntimeObject, UFunction* Setter, T&& InPropertyValue);
334
335 using FCachedProperty = UE::MovieScene::FCachedProperty;
336 using FVolatileProperty = UE::MovieScene::FVolatileProperty;
337
338 struct FResolvedPropertyAndFunction
339 {
341 TWeakObjectPtr<UFunction> SetterFunction;
342
343 MOVIESCENE_API FProperty* GetValidProperty() const;
344
345 MOVIESCENE_API void* GetContainerAddress() const;
346
347 template<typename ValueType>
348 ValueType* GetPropertyAddress() const
349 {
350 if (const FCachedProperty* CachedProperty = ResolvedProperty.TryGet<FCachedProperty>())
351 {
352 return CachedProperty->GetPropertyAddress<ValueType>();
353 }
354 else if (const FVolatileProperty* VolatileProperty = ResolvedProperty.TryGet<FVolatileProperty>())
355 {
356 return VolatileProperty->GetPropertyAddress<ValueType>();
357 }
358 else
359 {
360 return nullptr;
361 }
362 }
363
364 FResolvedPropertyAndFunction()
365 : ResolvedProperty()
366 , SetterFunction( nullptr )
367 {}
368 };
369
370 MOVIESCENE_API static FResolvedPropertyAndFunction FindPropertyAndFunction(const UObject* Object, FStringView InPropertyPath);
371
372 template <typename ValueType>
373 static bool TryGetPropertyValue(const FResolvedPropertyAndFunction& PropAndFunction, ValueType& OutValue)
374 {
375 if (const ValueType* Value = PropAndFunction.GetPropertyAddress<ValueType>())
376 {
377 OutValue = *Value;
378 return true;
379 }
380 return false;
381 }
382
384 MOVIESCENE_API const FResolvedPropertyAndFunction& FindOrAdd(const UObject& InObject);
385
386private:
387
389 TMap< FObjectKey, FResolvedPropertyAndFunction > RuntimeObjectToFunctionMap;
390
392 FString PropertyPath;
393
395 FName FunctionName;
396
398 FName PropertyName;
399
401};
402
404template<> MOVIESCENE_API void FTrackInstancePropertyBindings::CallFunction<bool>(UObject& InRuntimeObject, TCallTraits<bool>::ParamType PropertyValue);
405template<> MOVIESCENE_API bool FTrackInstancePropertyBindings::TryGetPropertyValue<bool>(const FResolvedPropertyAndFunction& PropAndFunction, bool& OutValue);
406template<> MOVIESCENE_API void FTrackInstancePropertyBindings::SetCurrentValue<bool>(UObject& Object, TCallTraits<bool>::ParamType InValue);
407
409template<> MOVIESCENE_API void FTrackInstancePropertyBindings::CallFunction<UObject*>(UObject& InRuntimeObject, UObject* PropertyValue);
410template<> MOVIESCENE_API bool FTrackInstancePropertyBindings::TryGetPropertyValue<UObject*>(const FResolvedPropertyAndFunction& PropAndFunction, UObject*& OutValue);
411template<> MOVIESCENE_API void FTrackInstancePropertyBindings::SetCurrentValue<UObject*>(UObject& Object, UObject* InValue);
412
413template<typename T>
414void FTrackInstancePropertyBindings::InvokeSetterFunction(UObject* InRuntimeObject, UFunction* Setter, T&& InPropertyValue)
415{
416 // CacheBinding already guarantees that the function has >= 1 parameters
417 const int32 ParmsSize = Setter->ParmsSize;
418
419 // This should all be const really, but ProcessEvent only takes a non-const void*
421
422 // By default we try and use the existing stack value
423 uint8* Params = reinterpret_cast<uint8*>(InputParameter);
424
425 check(InRuntimeObject && Setter);
426 if (Setter->ReturnValueOffset != MAX_uint16 || Setter->NumParms > 0)
427 {
428 // Function has a return value or multiple parameters, we need to initialize memory for the entire parameter pack
429 // We use alloca here (as in UObject::ProcessEvent) to avoid a heap allocation. Alloca memory survives the current function's stack frame.
430 Params = reinterpret_cast<uint8*>(FMemory_Alloca(ParmsSize));
431
432 bool bFirstProperty = true;
433 for (FProperty* Property = Setter->PropertyLink; Property; Property = Property->PropertyLinkNext)
434 {
435 // Initialize the parameter pack with any param properties that reside in the container
436 if (Property->IsInContainer(ParmsSize))
437 {
438 Property->InitializeValue_InContainer(Params);
439
440 // The first encountered property is assumed to be the input value so initialize this with the user-specified value from InPropertyValue
441 if (Property->HasAnyPropertyFlags(CPF_Parm) && !Property->HasAnyPropertyFlags(CPF_ReturnParm) && bFirstProperty)
442 {
443 const bool bIsValid = ensureMsgf(sizeof(T) == Property->GetElementSize(), TEXT("Property type does not match for Sequencer setter function %s::%s (%" SIZE_T_FMT "bytes != %ibytes"), *InRuntimeObject->GetName(), *Setter->GetName(), sizeof(T), Property->GetElementSize());
444 if (bIsValid)
445 {
446 Property->CopyCompleteValue(Property->ContainerPtrToValuePtr<void>(Params), &InPropertyValue);
447 }
448 else
449 {
450 return;
451 }
452 }
453 bFirstProperty = false;
454 }
455 }
456 }
457
458 // Now we have the parameters set up correctly, call the function
459 InRuntimeObject->ProcessEvent(Setter, Params);
460}
461
#define SIZE_T_FMT
Definition AndroidPlatformString.h:30
#define check(expr)
Definition AssertionMacros.h:314
#define ensureMsgf( InExpression, InFormat,...)
Definition AssertionMacros.h:465
#define checkf(expr, format,...)
Definition AssertionMacros.h:315
@ INDEX_NONE
Definition CoreMiscDefines.h:150
#define TEXT(x)
Definition Platform.h:1272
FPlatformTypes::int64 int64
A 64-bit signed integer.
Definition Platform.h:1127
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 FMemory_Alloca(Size)
Definition GenericPlatformMemory.h:218
#define MAX_uint16
Definition NumericLimits.h:20
@ CPF_Parm
Function/When call parameter.
Definition ObjectMacros.h:426
@ CPF_ReturnParm
Return value.
Definition ObjectMacros.h:429
@ RF_FinishDestroyed
FinishDestroy has been called on the object.
Definition ObjectMacros.h:579
@ RF_BeginDestroyed
BeginDestroy has been called on the object.
Definition ObjectMacros.h:578
float Val(const FString &Value)
Definition UnrealMath.cpp:3163
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTempIfPossible(T &&Obj) noexcept
Definition UnrealTemplate.h:538
uint8_t uint8
Definition binka_ue_file_header.h:8
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition UnrealType.h:3702
Definition NameTypes.h:617
Definition UnrealType.h:174
virtual void CallSetter(void *Container, const void *InValue) const
Definition UnrealType.h:367
Definition UnrealType.h:4175
Definition TrackInstancePropertyBindings.h:143
const FString & GetPropertyPath() const
Definition TrackInstancePropertyBindings.h:276
TOptional< ValueType > GetOptionalValue(const UObject &Object)
Definition TrackInstancePropertyBindings.h:237
static MOVIESCENE_API TOptional< UE::MovieScene::FSourcePropertyValue > StaticValue(const UObject *Object, FStringView InPropertyPath)
Definition TrackInstancePropertyBindings.cpp:470
const FName & GetPropertyName() const
Definition TrackInstancePropertyBindings.h:282
void CallFunction(UObject &InRuntimeObject, typename TCallTraits< ValueType >::ParamType PropertyValue)
Definition TrackInstancePropertyBindings.h:155
MOVIESCENE_API void CallFunctionForEnum(UObject &InRuntimeObject, int64 PropertyValue)
Definition TrackInstancePropertyBindings.cpp:580
static TOptional< ValueType > StaticValue(const UObject *Object, FStringView InPropertyPath)
Definition TrackInstancePropertyBindings.h:307
MOVIESCENE_API void CacheBinding(const UObject &InRuntimeObject)
Definition TrackInstancePropertyBindings.cpp:608
static MOVIESCENE_API TOptional< TPair< const FProperty *, UE::MovieScene::FSourcePropertyValue > > StaticPropertyAndValue(const UObject *Object, FStringView InPropertyPath)
Definition TrackInstancePropertyBindings.cpp:432
static MOVIESCENE_API FProperty * FindProperty(const UObject *Object, FStringView InPropertyPath)
Definition TrackInstancePropertyBindings.cpp:518
friend class FTrackInstancePropertyBindingsTests
Definition TrackInstancePropertyBindings.h:400
MOVIESCENE_API bool HasValidBinding(const UObject &Object)
Definition TrackInstancePropertyBindings.cpp:641
MOVIESCENE_API const UStruct * GetPropertyStruct(const UObject &Object)
Definition TrackInstancePropertyBindings.cpp:647
void SetCurrentValue(UObject &Object, typename TCallTraits< ValueType >::ParamType InValue)
Definition TrackInstancePropertyBindings.h:265
ValueType GetCurrentValue(const UObject &Object)
Definition TrackInstancePropertyBindings.h:220
MOVIESCENE_API FProperty * GetProperty(const UObject &Object)
Definition TrackInstancePropertyBindings.cpp:635
MOVIESCENE_API int64 GetCurrentValueForEnum(const UObject &Object)
Definition TrackInstancePropertyBindings.cpp:663
Definition PropertyPath.Build.cs:6
Definition Array.h:670
U * TryGet() UE_LIFETIMEBOUND
Definition TVariant.h:174
Definition Class.h:2476
uint8 NumParms
Definition Class.h:2487
uint16 ParmsSize
Definition Class.h:2489
uint16 ReturnValueOffset
Definition Class.h:2491
UE_FORCEINLINE_HINT FString GetName() const
Definition UObjectBaseUtility.h:439
bool HasAnyFlags(EObjectFlags FlagsToCheck) const
Definition UObjectBaseUtility.h:93
Definition Object.h:95
Definition Class.h:480
FProperty * PropertyLink
Definition Class.h:530
Definition ConstraintsManager.h:14
TCallTraitsParamTypeHelper< T, PassByValue >::ParamType ParamType
Definition UnrealTypeTraits.h:275
UE::Core::Private::Decay::TDecayNonReference< typenameTRemoveReference< T >::Type >::Type Type
Definition Decay.h:45
Definition Optional.h:131
Definition WeakFieldPtr.h:65
T * Get(bool bEvenIfPendingKill) const
Definition WeakFieldPtr.h:214
Definition WeakObjectPtrTemplates.h:25
Definition TrackInstancePropertyBindings.h:23
FProperty * GetValidProperty() const
Definition TrackInstancePropertyBindings.h:30
TWeakFieldPtr< FProperty > Property
Definition TrackInstancePropertyBindings.h:24
ValueType * GetPropertyAddress() const
Definition TrackInstancePropertyBindings.h:41
void * ContainerAddress
Definition TrackInstancePropertyBindings.h:26
int32 ArrayIndex
Definition TrackInstancePropertyBindings.h:28
Definition TrackInstancePropertyBindings.h:64
void SetContainerOffset(uint32 InOffset)
Definition TrackInstancePropertyBindings.h:86
void SetCheckStruct(TWeakObjectPtr< UScriptStruct > InScriptStruct)
Definition TrackInstancePropertyBindings.h:88
void SetCheckArrayIndex(int32 InArrayIndex)
Definition TrackInstancePropertyBindings.h:87
void * ResolveAddress(void *ContainerAddress, bool &bNeedsRecaching) const
Definition TrackInstancePropertyBindings.cpp:333
Definition TrackInstancePropertyBindings.h:100
FProperty * GetValidProperty() const
Definition TrackInstancePropertyBindings.h:108
const UObject * RootContainer
Definition TrackInstancePropertyBindings.h:101
ValueType * GetPropertyAddress() const
Definition TrackInstancePropertyBindings.h:124
void * GetLeafContainerAddress() const
Definition TrackInstancePropertyBindings.h:118
TWeakFieldPtr< FProperty > LeafProperty
Definition TrackInstancePropertyBindings.h:105
FString PropertyPath
Definition TrackInstancePropertyBindings.h:102
TArray< FVolatilePropertyStep > PropertySteps
Definition TrackInstancePropertyBindings.h:104
int32 LeafContainerStepIndex
Definition TrackInstancePropertyBindings.h:106