UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
AnimNode_Inertialization.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"
12
13#include "AnimNode_Inertialization.generated.h"
14
15
16// Inertialization: High-Performance Animation Transitions in 'Gears of War'
17// David Bollo
18// Game Developer Conference 2018
19//
20// https://www.gdcvault.com/play/1025165/Inertialization
21// https://www.gdcvault.com/play/1025331/Inertialization
22
23
24namespace UE::Anim
25{
26
27// Event that can be subscribed to request inertialization-based blends
29{
31
32public:
34
35 // Request to activate inertialization for a duration.
36 // If multiple requests are made on the same inertialization node, the minimum requested time will be used.
38
39 // Request to activate inertialization.
40 // If multiple requests are made on the same inertialization node, the minimum requested time will be used.
42
43 // Add a record of this request
45
46 virtual FName GetTag() const = 0;
47};
48
49} // namespace UE::Anim
50
51UENUM()
53{
54 Inactive, // Inertialization inactive
55 Pending, // Inertialization request pending... prepare to capture the pose difference and then switch to active
56 Active // Inertialization active... apply the previously captured pose difference
57};
58
59UENUM()
60enum class UE_DEPRECATED(5.4, "Internal private pose storage is now used by inertialization.") EInertializationBoneState : uint8
61{
62 Invalid, // Invalid bone (ie: bone was present in the skeleton but was not present in the pose when it was captured)
63 Valid, // Valid bone
64 Excluded // Valid bone that is to be excluded from the inertialization request
65};
66
67
68UENUM()
70{
71 Default, // Inertialize in local space (default)
72 WorldSpace, // Inertialize translation and rotation in world space (to conceal discontinuities in actor transform such snapping to a new attach parent)
73 WorldRotation // Inertialize rotation only in world space (to conceal discontinuities in actor orientation)
74};
75
77{
79
80 UE_DEPRECATED(5.3, "CurveUIDToArrayIndexLUT is no longer used.")
82
84
89
94
96 {
97 BlendedCurve.CopyFrom(Other.BlendedCurve);
98 return *this;
99 }
100
102 {
103 BlendedCurve.MoveFrom(Other.BlendedCurve);
104 return *this;
105 }
106
107 template <typename OtherAllocator>
112};
113
114USTRUCT()
116{
118
119 FTransform ComponentTransform;
120 TArray<FTransform> BoneTransforms;
125 FName AttachParentName;
126 float DeltaTime;
127
129 : ComponentTransform(FTransform::Identity)
130 , AttachParentName(NAME_None)
131 , DeltaTime(0.0f)
132 {
133 }
134
135
138 FInertializationPose& operator=(const FInertializationPose&) = default;
139 FInertializationPose& operator=(FInertializationPose&&) = default;
140
141 void InitFrom(const FCompactPose& Pose, const FBlendedCurve& InCurves, const FTransform& InComponentTransform, const FName& InAttachParentName, float InDeltaTime);
142};
143
145template <>
147{
148 enum { Value = false };
149};
151
152// Internal private structure used for storing a pose snapshots sparsely (i.e. when we may not have the full set of transform for every bone)
154{
157
158private:
159
160 // Transform of the component at the point of the snapshot
161 FTransform ComponentTransform;
162
163 // Has Root Motion
164 bool bHasRootMotion = false;
165
166 // Root Motion Delta at the point of the snapshot
167 FTransform RootMotionDelta;
168
169 // For each SkeletonPoseBoneIndex this array stores the index into the BoneTranslations, BoneRotations, and
170 // BoneScales arrays which contains that bone's data. Or INDEX_NONE if this bone's data is not in the snapshot.
171 TArray<int32> BoneIndices;
172
173 // Bone translation Data
174 TArray<FVector> BoneTranslations;
175
176 // Bone Rotation Data
177 TArray<FQuat> BoneRotations;
178
179 // Bone Scale Data
180 TArray<FVector> BoneScales;
181
182 // Curve Data
184
185 // Attached Parent object Name
186 FName AttachParentName = NAME_None;
187
188 // Delta Time since last snapshot
189 float DeltaTime = 0.0f;
190
191 void InitFrom(
192 const FCompactPose& Pose,
193 const FBlendedCurve& InCurves,
194 const UE::Anim::FStackAttributeContainer& Attributes,
197 const float InDeltaTime);
198
199 bool IsEmpty() const;
200 void Empty();
201};
202
203USTRUCT()
205{
207
209 FVector RotationAxis;
211
213 float TranslationSpeed;
214
215 float RotationAngle;
216 float RotationSpeed;
217
218 float ScaleMagnitude;
219 float ScaleSpeed;
220
222 : TranslationDirection(FVector::ZeroVector)
223 , RotationAxis(FVector::ZeroVector)
224 , ScaleAxis(FVector::ZeroVector)
226 , TranslationSpeed(0.0f)
227 , RotationAngle(0.0f)
228 , RotationSpeed(0.0f)
229 , ScaleMagnitude(0.0f)
230 , ScaleSpeed(0.0f)
231 {
232 }
233
234 void Clear()
235 {
237 RotationAxis = FVector::ZeroVector;
240 TranslationSpeed = 0.0f;
241 RotationAngle = 0.0f;
242 RotationSpeed = 0.0f;
243 ScaleMagnitude = 0.0f;
244 ScaleSpeed = 0.0f;
245 }
246};
247
249{
250 float Delta = 0.0f;
251 float Derivative = 0.0f;
252
254
255 void Clear()
256 {
257 Value = 0.0f;
258 Delta = 0.0f;
259 Derivative = 0.0f;
260 }
261};
262
263USTRUCT()
265{
267
270 {
271 }
272
273 void Reset(uint32 NumBonesSlack = 0)
274 {
276 CurveDiffs.Empty();
278 }
279
281
282 void InitFrom(const FCompactPose& Pose, const FBlendedCurve& Curves, const FTransform& ComponentTransform, const FName& AttachParentName, const FInertializationPose& Prev1, const FInertializationPose& Prev2, const UE::Anim::FCurveFilter& CurveFilter);
283 void ApplyTo(FCompactPose& Pose, FBlendedCurve& Curves, float InertializationElapsedTime, float InertializationDuration, TArrayView<const float> InertializationDurationPerBone) const;
284
286 {
288 }
289
290private:
291
295
297};
298
299USTRUCT(BlueprintInternalUseOnly)
301#if CPP
303#endif
304{
306
307 UPROPERTY(EditAnywhere, Category = Links)
308 FPoseLink Source;
309
310#if WITH_EDITORONLY_DATA
311 void SetTag(FName InTag) { Tag = InTag; }
312#endif
313 FName GetTag() { return Tag; }
314
315private:
316
317 // Optional default blend profile to use when no blend profile is supplied with the inertialization request
318 UPROPERTY(EditAnywhere, Category = BlendProfile, meta = (UseAsBlendProfile = true))
319 TObjectPtr<UBlendProfile> DefaultBlendProfile = nullptr;
320
321 // List of curves that should not use inertial blending. These curves will instantly change when inertialization begins.
322 UPROPERTY(EditAnywhere, Category = Filter)
323 TArray<FName> FilteredCurves;
324
325 // List of bones that should not use inertial blending. These bones will change instantly when the animation switches.
326 UPROPERTY(EditAnywhere, Category = Filter)
327 TArray<FBoneReference> FilteredBones;
328
329#if WITH_EDITORONLY_DATA
330 UE_DEPRECATED(5.4, "Preallocate Memory has been deprecated.")
331 UPROPERTY(meta = (DeprecatedProperty, DeprecationMessage = "Preallocate Memory has been deprecated."))
333#endif
334
338 UPROPERTY(EditAnywhere, Category = Blending)
339 bool bResetOnBecomingRelevant = false;
340
347 UPROPERTY(EditAnywhere, Category = Requests)
348 bool bForwardRequestsThroughSkippedCachedPoseNodes = true;
349
350 UPROPERTY()
352
353public: // FAnimNode_Inertialization
354
355 // Note: We need to explicitly disable warnings on these constructors/operators for clang to be happy with deprecated variables
364
365 // Request to activate inertialization for a duration.
366 // If multiple requests are made on the same inertialization node, the minimum requested time will be used.
367 //
368 ENGINE_API virtual void RequestInertialization(float Duration, const UBlendProfile* BlendProfile);
369
370 // Request to activate inertialization.
371 // If multiple requests are made on the same inertialization node, the minimum requested time will be used.
372 //
373 ENGINE_API virtual void RequestInertialization(const FInertializationRequest& InertializationRequest);
374
375 // Log an error when a node wants to inertialize but no inertialization ancestor node exists
376 //
377 static ENGINE_API void LogRequestError(const FAnimationUpdateContext& Context, const int32 NodePropertyIndex);
379
380public: // FAnimNode_Base
381
382 ENGINE_API virtual void Initialize_AnyThread(const FAnimationInitializeContext& Context) override;
383 ENGINE_API virtual void CacheBones_AnyThread(const FAnimationCacheBonesContext& Context) override;
384 ENGINE_API virtual void Update_AnyThread(const FAnimationUpdateContext& Context) override;
385 ENGINE_API virtual void Evaluate_AnyThread(FPoseContext& Output) override;
386 ENGINE_API virtual void GatherDebugData(FNodeDebugData& DebugData) override;
387
388 ENGINE_API virtual bool NeedsDynamicReset() const override;
390
392
394
395 UE_DEPRECATED(5.4, "This function is longer called by the node internally as inertialization method is now private.")
397
398 UE_DEPRECATED(5.4, "This function is longer called by the node internally as inertialization method is now private.")
399 ENGINE_API virtual void ApplyInertialization(FPoseContext& Context, const FInertializationPoseDiff& PoseDiff, float ElapsedTime, float Duration, TArrayView<const float> DurationPerBone);
400
402
403private:
404
408 void Deactivate();
409
421 void InitFrom(
422 const FCompactPose& InPose,
423 const FBlendedCurve& InCurves,
424 const UE::Anim::FStackAttributeContainer& InAttributes,
425 const FTransform& ComponentTransform,
426 const FName AttachParentName,
429
437 void ApplyTo(FCompactPose& InOutPose, FBlendedCurve& InOutCurves, UE::Anim::FStackAttributeContainer& InOutAttributes);
438
439 // Snapshots of the actor pose generated as output.
440 FInertializationSparsePose PrevPoseSnapshot;
441 FInertializationSparsePose CurrPoseSnapshot;
442
443 // Elapsed delta time between calls to evaluate
444 float DeltaTime = 0.0f;
445
446 // Pending inertialization requests
448 TArray<FInertializationRequest> RequestQueue;
449
450 // Update Counter for detecting being relevant
451 FGraphTraversalCounter UpdateCounter;
452
453 // Inertialization state
455
456 // Amount of time elapsed during the Inertialization
457 float InertializationElapsedTime = 0.0f;
458
459 // Inertialization duration for the main inertialization request (used for curve blending and deficit tracking)
460 float InertializationDuration = 0.0f;
461
462 // Inertialization durations indexed by skeleton bone index (used for per-bone blending)
463 TCustomBoneIndexArray<float, FSkeletonPoseBoneIndex> InertializationDurationPerBone;
464
465 // Maximum of InertializationDuration and all entries in InertializationDurationPerBone (used for knowing when to shutdown the inertialization)
466 float InertializationMaxDuration = 0.0f;
467
468 // Inertialization deficit (for tracking and reducing 'pose melting' when thrashing inertialization requests)
469 float InertializationDeficit = 0.0f;
470
471 // Inertialization pose differences
472 TArray<int32> BoneIndices;
473 TArray<FVector3f> BoneTranslationDiffDirection;
474 TArray<float> BoneTranslationDiffMagnitude;
475 TArray<float> BoneTranslationDiffSpeed;
476 TArray<FVector3f> BoneRotationDiffAxis;
477 TArray<float> BoneRotationDiffAngle;
478 TArray<float> BoneRotationDiffSpeed;
479 TArray<FVector3f> BoneScaleDiffAxis;
480 TArray<float> BoneScaleDiffMagnitude;
481 TArray<float> BoneScaleDiffSpeed;
482 FVector3f RootTranslationVelocityDiffDirection;
483 float RootTranslationVelocityDiffMagnitude;
484 FVector3f RootRotationVelocityDiffDirection;
485 float RootRotationVelocityDiffMagnitude;
486 FVector3f RootScaleVelocityDiffDirection;
487 float RootScaleVelocityDiffMagnitude;
488
489 // Curve differences
491
492 // Temporary storage for curve data of the Destination Pose
493 TBaseBlendedCurve<TInlineAllocator<8>, UE::Anim::FCurveElement> PoseCurveData;
494
495public: // IBoneReferenceSkeletonProvider
496 ENGINE_API class USkeleton* GetSkeleton(bool& bInvalidSkeletonIsError, const IPropertyHandle* PropertyHandle) override;
497
498private:
499
500 // Cached curve filter built from FilteredCurves
501 UE::Anim::FCurveFilter CurveFilter;
502
503 // Cache compact pose bone index for FilteredBones
505
506// if ANIM_TRACE_ENABLED - these properties are only used for debugging when ANIM_TRACE_ENABLED == 1
507
508 // Description for the current inertialization request
509 FString InertializationRequestDescription;
510
511 // Node Id for the current inertialization request
512 int32 InertializationRequestNodeId = INDEX_NONE;
513
514 // Anim Instance for the current inertialization request
516 TObjectPtr<UObject> InertializationRequestAnimInstance = nullptr;
517
518// endif ANIM_TRACE_ENABLED
519
520};
OODEFFUNC typedef const int const char * function
Definition oodle2.h:710
@ Valid
Definition AndroidInputInterface.h:103
#define DECLARE_ANIMGRAPH_MESSAGE_API(ClassName, ModuleApi)
Definition AnimNodeMessages.h:23
EInertializationState
Definition AnimNode_Inertialization.h:53
EInertializationSpace
Definition AnimNode_Inertialization.h:70
@ INDEX_NONE
Definition CoreMiscDefines.h:150
#define UE_DEPRECATED(Version, Message)
Definition CoreMiscDefines.h:302
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
ETeleportType
Definition EngineTypes.h:2401
#define PRAGMA_ENABLE_DEPRECATION_WARNINGS
Definition GenericPlatformCompilerPreSetup.h:12
#define PRAGMA_DISABLE_DEPRECATION_WARNINGS
Definition GenericPlatformCompilerPreSetup.h:8
#define UPROPERTY(...)
UObject definition macros.
Definition ObjectMacros.h:744
#define GENERATED_BODY(...)
Definition ObjectMacros.h:765
#define UENUM(...)
Definition ObjectMacros.h:749
#define USTRUCT(...)
Definition ObjectMacros.h:746
UE_INTRINSIC_CAST UE_REWRITE constexpr std::remove_reference_t< T > && MoveTemp(T &&Obj) noexcept
Definition UnrealTemplate.h:520
uint8_t uint8
Definition binka_ue_file_header.h:8
uint16_t uint16
Definition binka_ue_file_header.h:7
uint32_t uint32
Definition binka_ue_file_header.h:6
Definition NameTypes.h:617
Definition Interface_BoneReferenceSkeletonProvider.h:19
Definition ArrayView.h:139
Definition Array.h:670
Definition ContainerAllocationPolicies.h:830
Definition ContainerAllocationPolicies.h:894
Definition BlendProfile.h:132
Definition AnimNodeMessages.h:81
Definition AnimNode_Inertialization.h:29
static ENGINE_API const FName Attribute
Definition AnimNode_Inertialization.h:33
virtual void RequestInertialization(float InRequestedDuration, const UBlendProfile *InBlendProfile=nullptr)=0
virtual void AddDebugRecord(const FAnimInstanceProxy &InSourceProxy, int32 InSourceNodeId)=0
virtual FName GetTag() const =0
Definition CustomBoneIndexArray.h:43
Definition Object.h:95
Definition Skeleton.h:295
Definition ByteSwap.h:14
Definition AnimationAsset.h:42
Definition AdvancedWidgetsModule.cpp:13
@ false
Definition radaudio_common.h:23
Definition AnimInstanceProxy.h:144
Definition AnimNodeBase.h:853
Definition AnimNode_DeadBlending.h:35
Definition AnimNode_Inertialization.h:304
FName GetTag()
Definition AnimNode_Inertialization.h:313
Definition AnimNodeBase.h:337
Definition AnimNodeBase.h:324
Definition AnimNodeBase.h:354
Definition AnimCurveTypes.h:1041
Definition AnimCurveTypes.h:1049
Definition BoneReference.h:14
Definition BoneIndices.h:63
Definition BonePose.h:347
Definition AnimTypes.h:144
Definition AnimNode_Inertialization.h:249
void Clear()
Definition AnimNode_Inertialization.h:255
float Derivative
Definition AnimNode_Inertialization.h:251
float Delta
Definition AnimNode_Inertialization.h:250
Definition AnimNode_Inertialization.h:77
FInertializationCurve(FInertializationCurve &&Other)
Definition AnimNode_Inertialization.h:90
FBlendedHeapCurve BlendedCurve
Definition AnimNode_Inertialization.h:78
void InitFrom(const TBaseBlendedCurve< OtherAllocator > &Other)
Definition AnimNode_Inertialization.h:108
TArray< uint16 > CurveUIDToArrayIndexLUT
Definition AnimNode_Inertialization.h:81
FInertializationCurve & operator=(const FInertializationCurve &Other)
Definition AnimNode_Inertialization.h:95
FInertializationCurve & operator=(FInertializationCurve &&Other)
Definition AnimNode_Inertialization.h:101
Definition AnimInertializationRequest.h:15
Definition AnimNode_Inertialization.h:154
Definition AnimNodeBase.h:642
Definition AnimNodeBase.h:479
Definition AnimNodeBase.h:750
Definition BoneIndices.h:79
Definition AnimCurveTypes.h:487
void MoveFrom(TBaseBlendedCurve &CurveToMoveFrom)
Definition AnimCurveTypes.h:1002
void CopyFrom(const TBaseBlendedCurve< OtherAllocator, OtherElementType > &InCurveToCopyFrom)
Definition AnimCurveTypes.h:977
Definition ObjectPtr.h:488
Definition UseBitwiseSwap.h:13
@ Value
Definition UseBitwiseSwap.h:15
Definition AnimCurveTypes.h:418
float Value
Definition AnimCurveTypes.h:442
Definition AnimCurveFilter.h:68
Definition AttributesRuntime.h:40
static CORE_API const TVector< double > ZeroVector
Definition Vector.h:79