UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ConstraintHandle.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
4#include "Chaos/Core.h"
5#include "Chaos/Declares.h"
6#include "Chaos/Vector.h"
8
9// Set to 1 to help trap erros in the constraint management which typically manifests as a dangling constraint handle in the IslandManager
10//
11// WARNING: Do not submit with either of these set to 1 !!
12//
13#ifndef CHAOS_CONSTRAINTHANDLE_DEBUG_ENABLED
14#define CHAOS_CONSTRAINTHANDLE_DEBUG_ENABLED 0
15#endif
16#ifndef CHAOS_CONSTRAINTHANDLE_DEBUG_DETAILED_ENABLED
17#define CHAOS_CONSTRAINTHANDLE_DEBUG_DETAILED_ENABLED (CHAOS_CONSTRAINTHANDLE_DEBUG_ENABLED && 0)
18#endif
19
20// This is a proxy for not allowing the above to be checked in - CIS should fail if it is left enabled
21#if UE_BUILD_SHIPPING || UE_BUILD_TEST
22static_assert(CHAOS_CONSTRAINTHANDLE_DEBUG_ENABLED == 0, "CHAOS_CONSTRAINTHANDLE_DEBUG_ENABLED should be 0");
23static_assert(CHAOS_CONSTRAINTHANDLE_DEBUG_DETAILED_ENABLED == 0, "CHAOS_CONSTRAINTHANDLE_DEBUG_DETAILED_ENABLED should be 0");
24#endif
25
26namespace Chaos
27{
28 class FPBDConstraintContainer;
29 class FPBDIndexedConstraintContainer;
30
33
34 namespace Private
35 {
36 class FPBDIslandConstraint;
37 }
38
49 {
50 public:
52 : TypeName(InName)
53 , BaseType(InBaseType)
54 {
55 }
56
64
68 bool IsA(const FConstraintHandleTypeID& TypeID) const
69 {
70 if (TypeID.TypeName == TypeName)
71 {
72 return true;
73 }
74 if (BaseType != nullptr)
75 {
76 return BaseType->IsA(TypeID);
77 }
78 return false;
79 }
80
81 FString ToString() const
82 {
83 return TypeName.ToString();
84 }
85
86 private:
87 FName TypeName;
88 const FConstraintHandleTypeID* BaseType;
89 };
90
91
102 {
103 public:
105
107 : ConstraintContainer(nullptr)
108 , GraphEdge(nullptr)
109 {
110 }
111
117
119 {
120 // Make sure we are not still in the graph
121 check(GraphEdge == nullptr);
122 }
123
124 virtual bool IsValid() const
125 {
126 return (ConstraintContainer != nullptr);
127 }
128
133
135 {
136 return ConstraintContainer;
137 }
138
140 {
141 return (GraphEdge != nullptr);
142 }
143
148
149 // NOTE: Should only be called by the IslandManager
151 {
152 // Check for double add
153 check((InEdge == nullptr) || (GraphEdge == nullptr));
154
156 }
157
159
160 virtual void SetEnabled(bool InEnabled) = 0;
161
162 virtual bool IsEnabled() const = 0;
163
164 virtual bool IsProbe() const { return false; }
165
166 // Does this constraint have the concept of sleep? (only really used for debug validation)
167 virtual bool SupportsSleeping() const { return false; }
168
169 // Can this constraint connect sleeping and active particles for partial island sleeping?
170 virtual bool SupportsPartialIslandSleeping() const { return false; }
171
172 virtual bool IsSleeping() const { return false; }
173 virtual void SetIsSleeping(const bool bInIsSleeping) {}
174
175 // Total net linear impulse applied by the velocity-based dynamics (VBD) solver (velocity iterations only).
176 virtual FVec3f GetNetLinearImpulse() const { return FVec3f(0); }
177
178 virtual bool WasAwakened() const { return false; }
179 virtual void SetWasAwakened(const bool bInWasAwakened) {}
180
181 // Implemented in ConstraintContainer.h
182 int32 GetContainerId() const;
183
184 // Implemented in ConstraintContainer.h
185 template<typename T> T* As();
186 template<typename T> const T* As() const;
187
188 // For use when you absolutely know the type (asserted in non-shipping)
189 template<typename T> T* AsUnsafe() { check(As<T>() != nullptr); return static_cast<T*>(this); }
190 template<typename T> const T* AsUnsafe() const { check(As<T>() != nullptr); return static_cast<const T*>(this); }
191
192 const FConstraintHandleTypeID& GetType() const;
193
195 {
196 static FConstraintHandleTypeID STypeID(TEXT("FConstraintHandle"), nullptr);
197 return STypeID;
198 }
199
201 {
202 static FConstraintHandleTypeID STypeID(TEXT("InvalidConstraintHandle"), nullptr);
203 return STypeID;
204 }
205
206 // Deprecated API
207 UE_DEPRECATED(5.3, "Use GetConstraintGraphEdge") int32 GetConstraintGraphIndex() const { return INDEX_NONE; }
208 UE_DEPRECATED(5.3, "Not supported") void SetConstraintGraphIndex(const int32 InIndex) const {}
209
210 protected:
212
214
216 };
217
218
227 {
228 public:
233
238
240 {
241 static FConstraintHandleTypeID STypeID(TEXT("FIntrusiveConstraintHandle"), &FConstraintHandle::StaticType());
242 return STypeID;
243 }
244 };
245
246
254 template<typename T_CONSTRAINT>
256 {
257 public:
259
264
269
271 {
272 return static_cast<FConstraint*>(this);
273 }
274
276 {
277 return static_cast<const FConstraint*>(this);
278 }
279 };
280
281
282
288 template<class T_CONTAINER>
290 {
291 public:
293 using FConstraintContainerHandle = typename FConstraintContainer::FConstraintContainerHandle;
294
295 FConstraintContainerHandle* AllocHandle(FConstraintContainer* ConstraintContainer, int32 ConstraintIndex) { return new FConstraintContainerHandle(ConstraintContainer, ConstraintIndex); }
296
298 };
299
300
307 {
308 public:
310 : Handle(nullptr)
311 {
312#if CHAOS_CONSTRAINTHANDLE_DEBUG_ENABLED
314#endif
315 }
316
318 : Handle(InHandle)
319 {
320#if CHAOS_CONSTRAINTHANDLE_DEBUG_ENABLED
322#endif
323 }
324
325 FConstraintHandle* operator->() const { return Handle; }
326 operator FConstraintHandle* () const { return Handle; }
327 FConstraintHandle* Get() const { return Handle; }
328
330 {
331 return ::GetTypeHash(V.Handle);
332 }
333
334 private:
335 FConstraintHandle* Handle;
336
337#if CHAOS_CONSTRAINTHANDLE_DEBUG_ENABLED
338 public:
339 const FGeometryParticleHandle* GetParticle0() const { return Particles[0]; }
340 const FGeometryParticleHandle* GetParticle1() const { return Particles[1]; }
341
342 private:
344
345 const FConstraintHandleTypeID* ConstraintType;
346 const FGeometryParticleHandle* Particles[2];
347#endif
348 };
349}
OODEFFUNC typedef void(OODLE_CALLBACK t_fp_OodleCore_Plugin_Free)(void *ptr)
#define check(expr)
Definition AssertionMacros.h:314
#define CHAOS_CONSTRAINTHANDLE_DEBUG_DETAILED_ENABLED
Definition ConstraintHandle.h:17
#define CHAOS_CONSTRAINTHANDLE_DEBUG_ENABLED
Definition ConstraintHandle.h:14
@ INDEX_NONE
Definition CoreMiscDefines.h:150
#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
uint32_t uint32
Definition binka_ue_file_header.h:6
A debugging utility for tracking down dangling constraint issues This acts as a FConstraintHandle*,...
Definition ConstraintHandle.h:307
friend uint32 GetTypeHash(const FConstraintHandleHolder &V)
Definition ConstraintHandle.h:329
FConstraintHandle * operator->() const
Definition ConstraintHandle.h:325
FConstraintHandleHolder()
Definition ConstraintHandle.h:309
FConstraintHandleHolder(FConstraintHandle *InHandle)
Definition ConstraintHandle.h:317
FConstraintHandle * Get() const
Definition ConstraintHandle.h:327
A type id for constraint handles to support safe up/down casting (including intermediate classes in t...
Definition ConstraintHandle.h:49
FString ToString() const
Definition ConstraintHandle.h:81
bool IsA(const FConstraintHandleTypeID &TypeID) const
Whether this type can be cast to the specified type.
Definition ConstraintHandle.h:68
FConstraintHandleTypeID(const FName &InName, const FConstraintHandleTypeID *InBaseType=nullptr)
Definition ConstraintHandle.h:51
static const FConstraintHandleTypeID InvalidTypeID()
An invalid constraint handle type for initialization and invalidation.
Definition ConstraintHandle.h:60
Base class for constraint handles.
Definition ConstraintHandle.h:102
FConstraintHandle(FPBDConstraintContainer *InContainer)
Definition ConstraintHandle.h:112
T * AsUnsafe()
Definition ConstraintHandle.h:189
virtual ~FConstraintHandle()
Definition ConstraintHandle.h:118
const FPBDConstraintContainer * GetContainer() const
Definition ConstraintHandle.h:134
virtual bool IsValid() const
Definition ConstraintHandle.h:124
virtual bool IsEnabled() const =0
FPBDConstraintContainer * ConstraintContainer
Definition ConstraintHandle.h:213
const T * AsUnsafe() const
Definition ConstraintHandle.h:190
virtual bool IsProbe() const
Definition ConstraintHandle.h:164
virtual void SetEnabled(bool InEnabled)=0
virtual TVec2< FGeometryParticleHandle * > GetConstrainedParticles() const =0
FConstraintHandle()
Definition ConstraintHandle.h:106
Private::FPBDIslandConstraint * GraphEdge
Definition ConstraintHandle.h:215
virtual void SetIsSleeping(const bool bInIsSleeping)
Definition ConstraintHandle.h:173
bool IsInConstraintGraph() const
Definition ConstraintHandle.h:139
UE_DEPRECATED(5.3, "Use GetConstraintGraphEdge") int32 GetConstraintGraphIndex() const
Definition ConstraintHandle.h:207
int32 GetContainerId() const
Definition PBDConstraintContainer.h:117
const FConstraintHandleTypeID & GetType() const
Definition PBDConstraintContainer.h:126
void SetConstraintGraphEdge(Private::FPBDIslandConstraint *InEdge)
Definition ConstraintHandle.h:150
virtual bool SupportsPartialIslandSleeping() const
Definition ConstraintHandle.h:170
virtual FVec3f GetNetLinearImpulse() const
Definition ConstraintHandle.h:176
virtual bool SupportsSleeping() const
Definition ConstraintHandle.h:167
static const FConstraintHandleTypeID & StaticType()
Definition ConstraintHandle.h:194
Private::FPBDIslandConstraint * GetConstraintGraphEdge() const
Definition ConstraintHandle.h:144
virtual void SetWasAwakened(const bool bInWasAwakened)
Definition ConstraintHandle.h:179
T * As()
Definition PBDConstraintContainer.h:136
virtual bool IsSleeping() const
Definition ConstraintHandle.h:172
static const FConstraintHandleTypeID & InvalidType()
Definition ConstraintHandle.h:200
UE_DEPRECATED(5.3, "Not supported") void SetConstraintGraphIndex(const int32 InIndex) const
Definition ConstraintHandle.h:208
FPBDConstraintContainer * GetContainer()
Definition ConstraintHandle.h:129
virtual bool WasAwakened() const
Definition ConstraintHandle.h:178
Base class for constraints that are allocated at permanent memory addresses and inherit the handle.
Definition ConstraintHandle.h:227
FIntrusiveConstraintHandle()
Definition ConstraintHandle.h:229
static const FConstraintHandleTypeID & StaticType()
Definition ConstraintHandle.h:239
void SetContainer(FPBDConstraintContainer *InContainer)
Definition ConstraintHandle.h:234
Definition PBDConstraintContainer.h:19
Definition IslandManager.h:151
Definition ConstraintHandle.h:290
typename FConstraintContainer::FConstraintContainerHandle FConstraintContainerHandle
Definition ConstraintHandle.h:293
T_CONTAINER FConstraintContainer
Definition ConstraintHandle.h:292
FConstraintContainerHandle * AllocHandle(FConstraintContainer *ConstraintContainer, int32 ConstraintIndex)
Definition ConstraintHandle.h:295
void FreeHandle(FConstraintContainerHandle *Handle)
Definition ConstraintHandle.h:297
Definition ParticleHandle.h:436
Base class for constraints that are allocated at permanent memory addresses and inherit the handle.
Definition ConstraintHandle.h:256
void SetContainer(FPBDConstraintContainer *InContainer)
Definition ConstraintHandle.h:265
TIntrusiveConstraintHandle()
Definition ConstraintHandle.h:260
const FConstraint * GetConstraint() const
Definition ConstraintHandle.h:275
FConstraint * GetConstraint()
Definition ConstraintHandle.h:270
Definition Vector.h:407
Definition Vector.h:41
Definition NameTypes.h:617
CORE_API FString ToString() const
Definition UnrealNames.cpp:3537
Definition SkeletalMeshComponent.h:307
TVector< FRealSingle, 3 > FVec3f
Definition Core.h:27
TGeometryParticleHandle< FReal, 3 > FGeometryParticleHandle
Definition ParticleHandleFwd.h:24
Definition OverriddenPropertySet.cpp:45
Definition AnimNode_Constraint.h:27