UDocumentation UE5.7 10.02.2026 (Source)
API documentation for Unreal Engine 5.7
MovementComponent.h
Go to the documentation of this file.
1// Copyright Epic Games, Inc. All Rights Reserved.
2
7#pragma once
8
9#include "CoreMinimal.h"
11#include "Engine/EngineTypes.h"
15#include "MovementComponent.generated.h"
16
17class AActor;
18class APhysicsVolume;
19class UPrimitiveComponent;
22struct FCollisionShape;
23
24
25
27{
28 // Typically we want to depenetrate regardless of direction, so we can get all the way out of penetration quickly.
29 // Our rules for "moving with depenetration normal" only get us so far out of the object. We'd prefer to pop out by the full MTD amount.
30 // Depenetration moves (in ResolvePenetration) then ignore blocking overlaps to be able to move out by the MTD amount.
32
34
35 extern float PenetrationPullbackDistance;
36}
37
38
43UENUM(BlueprintType)
57
58
69UCLASS(ClassGroup=Movement, abstract, BlueprintType, MinimalAPI)
71{
73
74
79 UPROPERTY(BlueprintReadOnly, Transient, DuplicateTransient, Category=MovementComponent)
80 TObjectPtr<USceneComponent> UpdatedComponent;
81
85 UPROPERTY(BlueprintReadOnly, Transient, DuplicateTransient, Category=MovementComponent)
86 TObjectPtr<UPrimitiveComponent> UpdatedPrimitive;
87
92 EMoveComponentFlags MoveComponentFlags;
93
95 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=Velocity)
97
98protected:
99
106 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=PlanarMovement, meta=(editcondition=bConstrainToPlane))
107 FVector PlaneConstraintNormal;
108
114 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=PlanarMovement, meta=(editcondition=bConstrainToPlane))
115 FVector PlaneConstraintOrigin;
116
123 ENGINE_API FVector GetPlaneConstraintNormalFromAxisSetting(EPlaneConstraintAxisSetting AxisSetting) const;
124
125public:
126
128 UPROPERTY(EditAnywhere, BlueprintReadWrite, Category=MovementComponent)
129 uint8 bUpdateOnlyIfRendered:1;
130
135 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=MovementComponent)
136 uint8 bAutoUpdateTickRegistration:1;
137
143 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=MovementComponent)
144 uint8 bTickBeforeOwner:1;
145
147 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=MovementComponent)
148 uint8 bAutoRegisterUpdatedComponent:1;
149
154 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=PlanarMovement)
155 uint8 bConstrainToPlane:1;
156
158 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=PlanarMovement, meta=(editcondition=bConstrainToPlane))
159 uint8 bSnapToPlaneAtStart:1;
160
165 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=MovementComponent)
166 uint8 bAutoRegisterPhysicsVolumeUpdates:1;
167
173 UPROPERTY(EditAnywhere, BlueprintReadOnly, Category=MovementComponent, meta=(editcondition=bAutoRegisterPhysicsVolumeUpdates))
174 uint8 bComponentShouldUpdatePhysicsVolume:1;
175
176private:
177
178#if WITH_EDITOR
179 // Warned about trying to move something with static mobility.
181#endif
182
184 bool bInOnRegister;
185
187 bool bInInitializeComponent;
188
194 UPROPERTY(EditAnywhere, Category=PlanarMovement, meta=(editcondition=bConstrainToPlane))
195 EPlaneConstraintAxisSetting PlaneConstraintAxisSetting;
196
197public:
198 //~ Begin ActorComponent Interface
199 ENGINE_API virtual void TickComponent(float DeltaTime, enum ELevelTick TickType, FActorComponentTickFunction *ThisTickFunction) override;
200 ENGINE_API virtual void RegisterComponentTickFunctions(bool bRegister) override;
201 ENGINE_API virtual void PostLoad() override;
202 ENGINE_API virtual void Deactivate() override;
203 ENGINE_API virtual void Serialize(FArchive& Ar) override;
204
206 ENGINE_API virtual void InitializeComponent() override;
207
209 ENGINE_API virtual void OnRegister() override;
210
211
212#if WITH_EDITOR
213 ENGINE_API virtual void PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent) override;
215#endif // WITH_EDITOR
216
217 //~ End ActorComponent Interface
218
220 UFUNCTION(BlueprintCallable, Category="Components|Movement")
221 ENGINE_API virtual float GetGravityZ() const;
222
224 UFUNCTION(BlueprintCallable, Category="Components|Movement")
225 virtual float GetMaxSpeed() const;
226
232 UFUNCTION(BlueprintCallable, Category="Components|Movement")
233 ENGINE_API virtual bool IsExceedingMaxSpeed(float MaxSpeed) const;
234
236 UFUNCTION(BlueprintCallable, Category="Components|Movement")
237 virtual void StopMovementImmediately();
238
244 ENGINE_API virtual bool ShouldSkipUpdate(float DeltaTime) const;
245
247 UFUNCTION(BlueprintCallable, Category="Components|Movement")
248 ENGINE_API virtual APhysicsVolume* GetPhysicsVolume() const;
249
251 UFUNCTION()
252 ENGINE_API virtual void PhysicsVolumeChanged(class APhysicsVolume* NewVolume);
253
255 UFUNCTION(BlueprintCallable, Category="Components|Movement")
256 ENGINE_API virtual void SetUpdatedComponent(USceneComponent* NewUpdatedComponent);
257
259 ENGINE_API virtual bool IsInWater() const;
260
262 ENGINE_API virtual void UpdateTickRegistration();
263
272 ENGINE_API virtual void HandleImpact(const FHitResult& Hit, float TimeSlice=0.f, const FVector& MoveDelta = FVector::ZeroVector);
273
275 ENGINE_API virtual void UpdateComponentVelocity();
276
279
281 ENGINE_API virtual bool OverlapTest(const FVector& Location, const FQuat& RotationQuat, const ECollisionChannel CollisionChannel, const FCollisionShape& CollisionShape, const AActor* IgnoreActor) const;
282
290 bool MoveUpdatedComponent(const FVector& Delta, const FQuat& NewRotation, bool bSweep, FHitResult* OutHit = NULL, ETeleportType Teleport = ETeleportType::None);
291 bool MoveUpdatedComponent(const FVector& Delta, const FRotator& NewRotation, bool bSweep, FHitResult* OutHit = NULL, ETeleportType Teleport = ETeleportType::None);
292
294
295 ENGINE_API virtual bool MoveUpdatedComponentImpl(const FVector& Delta, const FQuat& NewRotation, bool bSweep, FHitResult* OutHit = NULL, ETeleportType Teleport = ETeleportType::None);
296
297public:
298
304 UFUNCTION(BlueprintCallable, Category="Components|Movement", meta=(DisplayName = "MoveUpdatedComponent", ScriptName = "MoveUpdatedComponent", AdvancedDisplay="bTeleport"))
305 ENGINE_API bool K2_MoveUpdatedComponent(FVector Delta, FRotator NewRotation, FHitResult& OutHit, bool bSweep = true, bool bTeleport = false);
306
316 ENGINE_API virtual bool SafeMoveUpdatedComponent(const FVector& Delta, const FQuat& NewRotation, bool bSweep, FHitResult& OutHit, ETeleportType Teleport = ETeleportType::None);
317 bool SafeMoveUpdatedComponent(const FVector& Delta, const FRotator& NewRotation, bool bSweep, FHitResult& OutHit, ETeleportType Teleport = ETeleportType::None);
318
324 ENGINE_API virtual FVector GetPenetrationAdjustment(const FHitResult& Hit) const;
325
334 bool ResolvePenetration(const FVector& Adjustment, const FHitResult& Hit, const FQuat& NewRotation);
335 bool ResolvePenetration(const FVector& Adjustment, const FHitResult& Hit, const FRotator& NewRotation);
336
338
339 ENGINE_API virtual bool ResolvePenetrationImpl(const FVector& Adjustment, const FHitResult& Hit, const FQuat& NewRotation);
340
341public:
342
350 ENGINE_API virtual FVector ComputeSlideVector(const FVector& Delta, const float Time, const FVector& Normal, const FHitResult& Hit) const;
351
362 ENGINE_API virtual float SlideAlongSurface(const FVector& Delta, float Time, const FVector& Normal, FHitResult &Hit, bool bHandleImpact = false);
363
371 ENGINE_API virtual void TwoWallAdjust(FVector &Delta, const FHitResult& Hit, const FVector &OldHitNormal) const;
372
381 ENGINE_API virtual void AddRadialForce(const FVector& Origin, float Radius, float Strength, ERadialImpulseFalloff Falloff);
382
392 ENGINE_API virtual void AddRadialImpulse(const FVector& Origin, float Radius, float Strength, ERadialImpulseFalloff Falloff, bool bVelChange);
393
400 UFUNCTION(BlueprintCallable, Category="Components|Movement|Planar")
401 ENGINE_API virtual void SetPlaneConstraintAxisSetting(EPlaneConstraintAxisSetting NewAxisSetting);
402
406 UFUNCTION(BlueprintCallable, Category="Components|Movement|Planar")
407 EPlaneConstraintAxisSetting GetPlaneConstraintAxisSetting() const;
408
415 UFUNCTION(BlueprintCallable, Category="Components|Movement|Planar")
416 ENGINE_API virtual void SetPlaneConstraintNormal(FVector PlaneNormal);
417
419 UFUNCTION(BlueprintCallable, Category="Components|Movement|Planar")
420 ENGINE_API virtual void SetPlaneConstraintFromVectors(FVector Forward, FVector Up);
421
423 UFUNCTION(BlueprintCallable, Category="Components|Movement|Planar")
424 ENGINE_API virtual void SetPlaneConstraintOrigin(FVector PlaneOrigin);
425
427 UFUNCTION(BlueprintCallable, Category = "Components|Movement|Planar")
428 ENGINE_API virtual void SetPlaneConstraintEnabled(bool bEnabled);
429
431 UFUNCTION(BlueprintCallable, Category="Components|Movement|Planar")
432 ENGINE_API const FVector& GetPlaneConstraintNormal() const;
433
438 UFUNCTION(BlueprintCallable, Category="Components|Movement|Planar")
439 ENGINE_API const FVector& GetPlaneConstraintOrigin() const;
440
445 UFUNCTION(BlueprintCallable, Category="Components|Movement|Planar")
446 ENGINE_API virtual FVector ConstrainDirectionToPlane(FVector Direction) const;
447
449 UFUNCTION(BlueprintCallable, Category="Components|Movement|Planar")
450 ENGINE_API virtual FVector ConstrainLocationToPlane(FVector Location) const;
451
453 UFUNCTION(BlueprintCallable, Category="Components|Movement|Planar")
454 ENGINE_API virtual FVector ConstrainNormalToPlane(FVector Normal) const;
455
457 UFUNCTION(BlueprintCallable, Category="Components|Movement|Planar")
458 ENGINE_API virtual void SnapUpdatedComponentToPlane();
459
461 virtual void OnTeleported() {};
462};
463
464
466// Inlines
467
469{
470 return 0.f;
471}
472
478
480{
481 return PlaneConstraintAxisSetting;
482}
483
485{
486 return SafeMoveUpdatedComponent(Delta, NewRotation.Quaternion(), bSweep, OutHit, Teleport);
487}
488
490{
491 return MoveUpdatedComponentImpl(Delta, NewRotation, bSweep, OutHit, Teleport);
492}
493
495{
496 return MoveUpdatedComponentImpl(Delta, NewRotation.Quaternion(), bSweep, OutHit, Teleport);
497}
498
499inline bool UMovementComponent::ResolvePenetration(const FVector& Adjustment, const FHitResult& Hit, const FQuat& NewRotation)
500{
501 return ResolvePenetrationImpl(Adjustment, Hit, NewRotation);
502}
503
504inline bool UMovementComponent::ResolvePenetration(const FVector& Adjustment, const FHitResult& Hit, const FRotator& NewRotation)
505{
506 return ResolvePenetrationImpl(Adjustment, Hit, NewRotation.Quaternion());
507}
#define NULL
Definition oodle2base.h:134
@ Normal
Definition AndroidInputInterface.h:116
ERadialImpulseFalloff
Definition ChaosEngineInterface.h:91
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
ELevelTick
Definition EngineBaseTypes.h:70
ETeleportType
Definition EngineTypes.h:2401
ECollisionChannel
Definition EngineTypes.h:1088
return true
Definition ExternalRpcRegistry.cpp:601
EPlaneConstraintAxisSetting
Definition MovementComponent.h:45
#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
#define UENUM(...)
Definition ObjectMacros.h:749
EMoveComponentFlags
Definition SceneComponent.h:56
uint8_t uint8
Definition binka_ue_file_header.h:8
Definition Actor.h:257
Definition PhysicsVolume.h:17
Definition Archive.h:1208
Definition ActorComponent.h:152
Definition MovementComponent.h:71
virtual ENGINE_API bool ResolvePenetrationImpl(const FVector &Adjustment, const FHitResult &Hit, const FQuat &NewRotation)
Definition MovementComponent.cpp:624
bool MoveUpdatedComponent(const FVector &Delta, const FQuat &NewRotation, bool bSweep, FHitResult *OutHit=NULL, ETeleportType Teleport=ETeleportType::None)
Definition MovementComponent.h:489
virtual ENGINE_API void UpdateComponentVelocity()
Definition MovementComponent.cpp:382
virtual ENGINE_API bool MoveUpdatedComponentImpl(const FVector &Delta, const FQuat &NewRotation, bool bSweep, FHitResult *OutHit=NULL, ETeleportType Teleport=ETeleportType::None)
Definition MovementComponent.cpp:526
bool ResolvePenetration(const FVector &Adjustment, const FHitResult &Hit, const FQuat &NewRotation)
Definition MovementComponent.h:499
EPlaneConstraintAxisSetting GetPlaneConstraintAxisSetting() const
Definition MovementComponent.h:479
virtual float GetMaxSpeed() const
Definition MovementComponent.h:468
virtual ENGINE_API bool SafeMoveUpdatedComponent(const FVector &Delta, const FQuat &NewRotation, bool bSweep, FHitResult &OutHit, ETeleportType Teleport=ETeleportType::None)
Definition MovementComponent.cpp:558
virtual void StopMovementImmediately()
Definition MovementComponent.h:473
Definition MovementComponent.h:27
float PenetrationPullbackDistance
Definition MovementComponent.cpp:593
float PenetrationOverlapCheckInflation
Definition MovementComponent.cpp:600
int32 MoveIgnoreFirstBlockingOverlap
Definition MovementComponent.cpp:548
@ false
Definition radaudio_common.h:23
Definition EngineBaseTypes.h:571
Definition CollisionQueryParams.h:43
Definition CollisionQueryParams.h:324
Definition CollisionShape.h:21
Definition HitResult.h:21
Definition UnrealType.h:6865
Definition ObjectPtr.h:488
CORE_API TQuat< T > Quaternion() const
static CORE_API const TVector< double > ZeroVector
Definition Vector.h:79