UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
PhysicsConstraintComponent.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
4#include "CoreMinimal.h"
9#include "PhysicsConstraintComponent.generated.h"
10
11#if UE_WITH_REMOTE_OBJECT_HANDLE
13#endif
14
15class AActor;
16class UPrimitiveComponent;
17struct FBodyInstance;
18
22UCLASS(ClassGroup=Physics, meta=(BlueprintSpawnableComponent), HideCategories=(Activation,"Components|Activation", Physics, Mobility), ShowCategories=("Physics|Components|PhysicsConstraint"), MinimalAPI)
23class UPhysicsConstraintComponent : public USceneComponent
24{
26
27
28 UPROPERTY(EditInstanceOnly, Category=Constraint)
30
35 UPROPERTY(EditAnywhere, Category=Constraint)
37
38
40 UPROPERTY(EditInstanceOnly, Category=Constraint)
42
47 UPROPERTY(EditAnywhere, Category=Constraint)
49
50
52 TWeakObjectPtr<UPrimitiveComponent> OverrideComponent1;
53
55 TWeakObjectPtr<UPrimitiveComponent> OverrideComponent2;
56
57
60
62 UPROPERTY(BlueprintAssignable)
64
66 UPROPERTY(BlueprintAssignable)
68
69public:
71 UPROPERTY(EditAnywhere, Category=ConstraintComponent, meta=(ShowOnlyInnerProperties))
72 FConstraintInstance ConstraintInstance;
73
74 //Begin UObject Interface
75 ENGINE_API virtual void BeginDestroy() override;
77#if WITH_EDITOR
78 ENGINE_API virtual void PostEditChangeChainProperty(FPropertyChangedChainEvent& PropertyChangedEvent) override;
79 ENGINE_API virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
80#endif // WITH_EDITOR
81#if WITH_EDITORONLY_DATA || UE_WITH_REMOTE_OBJECT_HANDLE
82 ENGINE_API virtual void Serialize(FArchive& Ar) override;
83#endif
84 //End UObject interface
85
86 //Begin ActorComponent interface
87#if WITH_EDITOR
88 ENGINE_API virtual void CheckForErrors() override;
89 ENGINE_API virtual void OnRegister() override;
90#endif // WITH_EDITOR
91 ENGINE_API virtual void EndPlay(const EEndPlayReason::Type EndPlayReason) override;
92 ENGINE_API virtual void OnUnregister() override;
93 ENGINE_API virtual void InitializeComponent() override;
94 //End ActorComponent interface
95
96#if UE_WITH_REMOTE_OBJECT_HANDLE
97 ENGINE_API virtual void PostMigrate(const struct FUObjectMigrationContext& MigrationContext) override;
99 ENGINE_API bool HasValidPhysicsState() const;
100#endif
101
102 UFUNCTION()
104
105 //~ Begin SceneComponent Interface
106#if WITH_EDITOR
107 ENGINE_API virtual void PostEditComponentMove(bool bFinished) override;
108#endif // WITH_EDITOR
109 //~ End SceneComponent Interface
110
113
116
119
122
124 UFUNCTION(BlueprintCallable, Category="Physics|Components|PhysicsConstraint")
125 ENGINE_API void SetConstrainedComponents(UPrimitiveComponent* Component1, FName BoneName1, UPrimitiveComponent* Component2, FName BoneName2);
126
128 UFUNCTION(BlueprintCallable, Category = "Physics|Components|PhysicsConstraint")
129 ENGINE_API void GetConstrainedComponents(UPrimitiveComponent*& OutComponent1, FName& OutBoneName1, UPrimitiveComponent*& OutComponent2, FName& OutBoneName2);
130
132 UFUNCTION(BlueprintCallable, Category="Physics|Components|PhysicsConstraint")
133 ENGINE_API void BreakConstraint();
134
141 UFUNCTION(BlueprintCallable, Category="Physics|Components|PhysicsConstraint")
142 ENGINE_API void SetLinearPositionDrive(bool bEnableDriveX, bool bEnableDriveY, bool bEnableDriveZ);
143
150 UFUNCTION(BlueprintCallable, Category="Physics|Components|PhysicsConstraint")
151 ENGINE_API void SetLinearVelocityDrive(bool bEnableDriveX, bool bEnableDriveY, bool bEnableDriveZ);
152
158 UFUNCTION(BlueprintCallable, Category="Physics|Components|PhysicsConstraint", meta=(DeprecatedFunction, DeprecationMessage = "Use SetOrientationDriveTwistAndSwing instead."))
160 {
161 SetOrientationDriveTwistAndSwing(bEnableTwistDrive, bEnableSwingDrive);
162 }
168 UFUNCTION(BlueprintCallable, Category = "Physics|Components|PhysicsConstraint")
169 ENGINE_API void SetOrientationDriveTwistAndSwing(bool bEnableTwistDrive, bool bEnableSwingDrive);
170
175 UFUNCTION(BlueprintCallable, Category = "Physics|Components|PhysicsConstraint")
176 ENGINE_API void SetOrientationDriveSLERP(bool bEnableSLERP);
177
178 UFUNCTION(BlueprintCallable, Category="Physics|Components|PhysicsConstraint", meta = (DeprecatedFunction, DeprecationMessage = "Use SetAngularVelocityDriveTwistAndSwing instead."))
180 {
181 SetAngularVelocityDriveTwistAndSwing(bEnableTwistDrive, bEnableSwingDrive);
182 }
183
189 UFUNCTION(BlueprintCallable, Category = "Physics|Components|PhysicsConstraint")
190 ENGINE_API void SetAngularVelocityDriveTwistAndSwing(bool bEnableTwistDrive, bool bEnableSwingDrive);
191
196 UFUNCTION(BlueprintCallable, Category = "Physics|Components|PhysicsConstraint")
197 ENGINE_API void SetAngularVelocityDriveSLERP(bool bEnableSLERP);
198
203 UFUNCTION(BlueprintCallable, Category = "Physics|Components|PhysicsConstraint")
204 ENGINE_API void SetAngularDriveMode(EAngularDriveMode::Type DriveMode);
205
207 UFUNCTION(BlueprintCallable, Category = "Physics|Components|PhysicsConstraint")
208 ENGINE_API void SetAngularDriveAccelerationMode(bool bAccelerationMode);
209
213 UFUNCTION(BlueprintCallable, Category="Physics|Components|PhysicsConstraint")
214 ENGINE_API void SetLinearPositionTarget(const FVector& InPosTarget);
215
219 UFUNCTION(BlueprintCallable, Category="Physics|Components|PhysicsConstraint")
220 ENGINE_API void SetLinearVelocityTarget(const FVector& InVelTarget);
221
227 UFUNCTION(BlueprintCallable, Category="Physics|Components|PhysicsConstraint")
228 ENGINE_API void SetLinearDriveParams(float PositionStrength, float VelocityStrength, float InForceLimit);
229
231 UFUNCTION(BlueprintCallable, Category = "Physics|Components|PhysicsConstraint")
232 ENGINE_API void SetLinearDriveAccelerationMode(bool bAccelerationMode);
233
237 UFUNCTION(BlueprintCallable, Category="Physics|Components|PhysicsConstraint")
238 ENGINE_API void SetAngularOrientationTarget(const FRotator& InPosTarget);
239
240
244 UFUNCTION(BlueprintCallable, Category="Physics|Components|PhysicsConstraint")
245 ENGINE_API void SetAngularVelocityTarget(const FVector& InVelTarget);
246
252 UFUNCTION(BlueprintCallable, Category="Physics|Components|PhysicsConstraint")
253 ENGINE_API void SetAngularDriveParams(float PositionStrength, float VelocityStrength, float InForceLimit);
254
255
260 UFUNCTION(BlueprintCallable, Category = "Physics|Components|PhysicsConstraint")
261 ENGINE_API void SetLinearXLimit(ELinearConstraintMotion ConstraintType, float LimitSize);
262
267 UFUNCTION(BlueprintCallable, Category = "Physics|Components|PhysicsConstraint")
268 ENGINE_API void SetLinearYLimit(ELinearConstraintMotion ConstraintType, float LimitSize);
269
274 UFUNCTION(BlueprintCallable, Category = "Physics|Components|PhysicsConstraint")
275 ENGINE_API void SetLinearZLimit(ELinearConstraintMotion ConstraintType, float LimitSize);
276
281 UFUNCTION(BlueprintCallable, Category = "Physics|Components|PhysicsConstraint")
282 ENGINE_API void SetAngularSwing1Limit(EAngularConstraintMotion MotionType, float Swing1LimitAngle);
283
288 UFUNCTION(BlueprintCallable, Category = "Physics|Components|PhysicsConstraint")
289 ENGINE_API void SetAngularSwing2Limit(EAngularConstraintMotion MotionType, float Swing2LimitAngle);
290
295 UFUNCTION(BlueprintCallable, Category = "Physics|Components|PhysicsConstraint")
296 ENGINE_API void SetAngularTwistLimit(EAngularConstraintMotion ConstraintType, float TwistLimitAngle);
297
302 UFUNCTION(BlueprintCallable, Category = "Physics|Components|PhysicsConstraint")
303 ENGINE_API void SetLinearBreakable(bool bLinearBreakable, float LinearBreakThreshold);
304
309 UFUNCTION(BlueprintCallable, Category = "Physics|Components|PhysicsConstraint")
310 ENGINE_API void SetLinearPlasticity(bool bLinearPlasticity, float LinearPlasticityThreshold, EConstraintPlasticityType PlasticityType);
311
316 UFUNCTION(BlueprintCallable, Category = "Physics|Components|PhysicsConstraint")
317 ENGINE_API void SetAngularBreakable(bool bAngularBreakable, float AngularBreakThreshold);
318
323 UFUNCTION(BlueprintCallable, Category = "Physics|Components|PhysicsConstraint")
324 ENGINE_API void SetAngularPlasticity(bool bAngularPlasticity, float AngularPlasticityThreshold);
325
329 UFUNCTION(BlueprintCallable, Category = "Physics|Components|PhysicsConstraint")
330 ENGINE_API void SetContactTransferScale(float ContactTransferScale);
331
333 UFUNCTION(BlueprintCallable, Category = "Physics|Components|PhysicsConstraint")
334 ENGINE_API float GetCurrentTwist() const;
335
337 UFUNCTION(BlueprintCallable, Category = "Physics|Components|PhysicsConstraint")
338 ENGINE_API float GetCurrentSwing1() const;
339
341 UFUNCTION(BlueprintCallable, Category = "Physics|Components|PhysicsConstraint")
342 ENGINE_API float GetCurrentSwing2() const;
343
350
351 // Pass in reference frame in. If the constraint is currently active, this will set its active local pose. Otherwise the change will take affect in InitConstraint.
352 UFUNCTION(BlueprintCallable, Category = "Physics|Components|PhysicsConstraint")
354
355 // Pass in reference position in (maintains reference orientation). If the constraint is currently active, this will set its active local pose. Otherwise the change will take affect in InitConstraint.
356 UFUNCTION(BlueprintCallable, Category = "Physics|Components|PhysicsConstraint")
358
359 // Pass in reference orientation in (maintains reference position). If the constraint is currently active, this will set its active local pose. Otherwise the change will take affect in InitConstraint.
360 UFUNCTION(BlueprintCallable, Category = "Physics|Components|PhysicsConstraint")
362
363 // If true, the collision between the two rigid bodies of the constraint will be disabled.
364 UFUNCTION(BlueprintCallable, Category = "Physics|Components|PhysicsConstraint")
365 ENGINE_API void SetDisableCollision(bool bDisableCollision);
366
367 // If true, joint projection is enabled. Projection is a semi-physics post-solve correction for fixing small errors, and a teleport for fixing larger errors. See SetProjectionParams
368 UFUNCTION(BlueprintCallable, Category = "Physics|Components|PhysicsConstraint")
369 ENGINE_API void SetProjectionEnabled(bool bProjectionEnabled);
370
371 // Is projection enabled. See SetProjectionEnabled
372 UFUNCTION(BlueprintCallable, Category = "Physics|Components|PhysicsConstraint")
373 bool IsProjectionEnabled() const;
374
385 UFUNCTION(BlueprintCallable, Category = "Physics|Components|PhysicsConstraint")
386 ENGINE_API void SetProjectionParams(float ProjectionLinearAlpha, float ProjectionAngularAlpha, float ProjectionLinearTolerance, float ProjectionAngularTolerance);
387
388 // Retrieve the constraint force most recently applied to maintain this constraint. Returns 0 forces if the constraint is not initialized or broken.
389 UFUNCTION(BlueprintCallable, Category = "Physics|Components|PhysicsConstraint")
390 ENGINE_API void GetConstraintForce(FVector& OutLinearForce, FVector& OutAngularForce);
391
392 // Retrieve the status of constraint being broken.
393 UFUNCTION(BlueprintCallable, Category = "Physics|Components|PhysicsConstraint")
394 ENGINE_API bool IsBroken();
395
397 UFUNCTION(BlueprintCallable, Category = "Physics|Components|PhysicsConstraint")
399
400#if WITH_EDITOR
402#endif
403
404protected:
405
407
410
413
420
423
426
428 ENGINE_API float GetConstraintScale() const;
429
430private:
431
432 bool bIsBrokenLocal;
433
435 ENGINE_API void OnConstraintBrokenWrapper(int32 ConstraintIndex);
436
438 ENGINE_API void OnPlasticDeformationWrapper(int32 ConstraintIndex);
439#if UE_WITH_REMOTE_OBJECT_HANDLE
441
443
445
447#endif
448};
449
EConstraintPlasticityType
Definition ChaosEngineInterface.h:173
EAngularConstraintMotion
Definition ChaosEngineInterface.h:114
ELinearConstraintMotion
Definition ChaosEngineInterface.h:187
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 UPROPERTY(...)
UObject definition macros.
Definition ObjectMacros.h:744
#define UFUNCTION(...)
Definition ObjectMacros.h:745
#define GENERATED_UCLASS_BODY(...)
Definition ObjectMacros.h:768
#define UCLASS(...)
Definition ObjectMacros.h:776
EComponentPhysicsStateChange
Definition PrimitiveComponent.h:220
EObjectMigrationSendType
Definition UObjectMigrationContext.h:43
Definition Actor.h:257
Definition Archive.h:1208
Definition NameTypes.h:617
Definition UnrealType.h:3087
Definition UniquePtr.h:107
Definition PhysicsConstraintTemplate.h:33
Definition ConstraintDrives.h:11
Definition ChaosEngineInterface.h:128
Type
Definition ChaosEngineInterface.h:130
Type
Definition EngineTypes.h:3431
Definition PhysicsObjectInternal.h:16
Definition BodyInstance.h:320
Definition EngineTypes.h:3650
Definition ConstraintInstance.h:1238
Definition ConstraintInstance.h:255
Definition UnrealType.h:7001
Definition UnrealType.h:6865
Definition UObjectMigrationContext.h:62
Definition ObjectPtr.h:488
Definition WeakObjectPtrTemplates.h:25