UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
ConstraintDrives.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2#pragma once
3
4#include "CoreMinimal.h"
6#include "EngineDefines.h"
7#include "ConstraintDrives.generated.h"
8
9UENUM()
11{
12 enum Type : int
13 {
18 };
19}
20
21
22USTRUCT()
24{
26
27
28 UPROPERTY(EditAnywhere, AdvancedDisplay, Category = Constraint, meta = (ClampMin = "0.0"))
29 float Stiffness;
30
32 UPROPERTY(EditAnywhere, AdvancedDisplay, Category = Constraint, meta = (ClampMin = "0.0"))
33 float Damping;
34
36 UPROPERTY(EditAnywhere, AdvancedDisplay, Category = Constraint, meta = (ClampMin = "0.0"))
37 float MaxForce;
38
40 UPROPERTY(EditAnywhere, Category = Constraint)
41 uint8 bEnablePositionDrive : 1;
42
44 UPROPERTY(EditAnywhere, Category = Constraint)
45 uint8 bEnableVelocityDrive : 1;
46
48
50 //void UpdatePhysXDrive_AssumesLocked(physx::PxD6Joint* Joint, int DriveType, bool bDriveEnabled) const;
51
56 //These functions may leave the struct in an invalid state unless calling UpdatePhysX* functions.
57 //They are only meant as helpers for FConstraintInstance
58 ENGINE_API void SetDriveParams(float InStiffness, float InDamping, float InForceLimit);
59
60
61};
62
64USTRUCT()
66{
68
69
70 UPROPERTY(EditAnywhere, Category = LinearMotor)
71 FVector PositionTarget;
72
74 UPROPERTY(EditAnywhere, Category = LinearMotor)
75 FVector VelocityTarget;
76
77 UPROPERTY(EditAnywhere, Category = LinearMotor)
79
80 UPROPERTY(EditAnywhere, Category = LinearMotor)
82
83 UPROPERTY(EditAnywhere, Category = LinearMotor)
85
87 UPROPERTY(EditAnywhere, Category = AngularMotor)
88 bool bAccelerationMode = true;
89
90#if WITH_EDITORONLY_DATA
92 UPROPERTY(config, meta = (DeprecatedProperty, DeprecationMessage = "Enable/disable of drives is done inside the individual constraint drives."))
95#endif
96
98
100 {
101 return XDrive.bEnablePositionDrive || YDrive.bEnablePositionDrive || ZDrive.bEnablePositionDrive;
102 }
103
105 {
106 return XDrive.bEnableVelocityDrive || YDrive.bEnableVelocityDrive || ZDrive.bEnableVelocityDrive;
107 }
108
109 //These functions may leave the struct in an invalid state unless calling UpdatePhysX* functions.
110 //They are only meant as helpers for FConstraintInstance
111 ENGINE_API void SetLinearPositionDrive(bool bEnableXDrive, bool bEnableYDrive, bool bEnableZDrive);
112 ENGINE_API void SetLinearVelocityDrive(bool bEnableXDrive, bool bEnableYDrive, bool bEnableZDrive);
113 ENGINE_API void SetDriveParams(float InStiffness, float InDamping, float InForceLimit);
114 ENGINE_API void SetDriveParams(const FVector& InStiffness, const FVector& InDamping, const FVector& InForceLimit);
115 ENGINE_API void GetDriveParams(float& OutStiffness, float& OutDamping, float& OutForceLimit) const;
116 ENGINE_API void GetDriveParams(FVector& OutStiffness, FVector& OutDamping, FVector& OutForceLimit) const;
117 ENGINE_API void SetAccelerationMode(bool bAccelerationMode);
118 ENGINE_API bool GetAccelerationMode() const;
119};
120
121
123USTRUCT()
125{
127
128
129 UPROPERTY(EditAnywhere, Category = LinearMotor, meta = (DisplayName="Twist"))
131
133 UPROPERTY(EditAnywhere, Category = LinearMotor, meta = (DisplayName = "Swing"))
135
137 UPROPERTY(EditAnywhere, Category = LinearMotor, meta = (DisplayName = "SLERP"))
139
141 UPROPERTY(EditAnywhere, Category = AngularMotor)
142 FRotator OrientationTarget;
143
145 UPROPERTY(EditAnywhere, Category = AngularMotor)
146 FVector AngularVelocityTarget;
147
149 UPROPERTY(EditAnywhere, Category = AngularMotor)
150 TEnumAsByte<enum EAngularDriveMode::Type> AngularDriveMode;
151
153 UPROPERTY(EditAnywhere, Category = AngularMotor)
154 bool bAccelerationMode = true;
155
157
158 bool IsOrientationDriveEnabled() const
159 {
160 if(AngularDriveMode == EAngularDriveMode::TwistAndSwing)
161 {
162 return TwistDrive.bEnablePositionDrive || SwingDrive.bEnablePositionDrive;
163 }
164 else
165 {
166 return SlerpDrive.bEnablePositionDrive;
167 }
168 }
169
171 {
172 if (AngularDriveMode == EAngularDriveMode::TwistAndSwing)
173 {
174 return TwistDrive.bEnableVelocityDrive || SwingDrive.bEnableVelocityDrive;
175 }
176 else
177 {
178 return SlerpDrive.bEnableVelocityDrive;
179 }
180
181 }
182
184 //void UpdatePhysXAngularDrive_AssumesLocked(physx::PxD6Joint* Joint) const;
185
186 //These functions may leave the struct in an invalid state unless calling UpdatePhysX* functions.
187 //They are only meant as helpers for FConstraintInstance
188 ENGINE_API void SetOrientationDriveTwistAndSwing(bool InEnableTwistDrive, bool InEnableSwingDrive);
189 ENGINE_API void SetOrientationDriveSLERP(bool InEnableSLERP);
190 ENGINE_API void SetAngularVelocityDriveTwistAndSwing(bool InEnableTwistDrive, bool InEnableSwingDrive);
191 ENGINE_API void SetAngularVelocityDriveSLERP(bool InEnableSLERP);
192 // Sets the three drive parameters (swing, twist and slerp) to the same value
193 ENGINE_API void SetDriveParams(float InStiffness, float InDamping, float InForceLimit);
194 // Sets drive parameters in the order swing, twist, slerp
195 ENGINE_API void SetDriveParams(const FVector& InStiffness, const FVector& InDamping, const FVector& InForceLimit);
196 // Gets just the swing drive parameters - assuming the single-float set function has previously been used
197 ENGINE_API void GetDriveParams(float& OutStiffness, float& OutDamping, float& OutForceLimit) const;
198 // Gets drive parameters in the order swing, twist, slerp
199 ENGINE_API void GetDriveParams(FVector& OutStiffness, FVector& OutDamping, FVector& OutForceLimit) const;
200 ENGINE_API void SetAngularDriveMode(EAngularDriveMode::Type DriveMode);
201 ENGINE_API void SetAccelerationMode(bool bAccelerationMode);
202 ENGINE_API bool GetAccelerationMode() const;
203};
UE_FORCEINLINE_HINT TSharedRef< CastToType, Mode > StaticCastSharedRef(TSharedRef< CastFromType, Mode > const &InSharedRef)
Definition SharedPointer.h:127
return true
Definition ExternalRpcRegistry.cpp:601
#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
USkinnedMeshComponent float
Definition SkinnedMeshComponent.h:60
uint8_t uint8
Definition binka_ue_file_header.h:8
Definition EnumAsByte.h:22
Definition ConstraintDrives.h:11
Type
Definition ConstraintDrives.h:13
@ SLERP
Definition ConstraintDrives.h:15
@ TwistAndSwing
Definition ConstraintDrives.h:17
Definition ConstraintDrives.h:125
bool IsVelocityDriveEnabled() const
Definition ConstraintDrives.h:170
Definition ConstraintDrives.h:24
uint8 bEnablePositionDrive
Definition ConstraintDrives.h:41
uint8 bEnableVelocityDrive
Definition ConstraintDrives.h:45
Definition ConstraintInstance.h:255
Definition ConstraintDrives.h:66
bool IsPositionDriveEnabled() const
Definition ConstraintDrives.h:99
bool IsVelocityDriveEnabled() const
Definition ConstraintDrives.h:104