RealDocs

UCharacterMovementComponent::SetGravityDirection

function Engine Blueprint Since 5.4
#include "GameFramework/CharacterMovementComponent.h"
Access: public Specifiers: UFUNCTIONBlueprintCallablevirtual

Description

Sets a custom local gravity direction for movement simulation, recomputing the cached world/gravity-space transforms used to orient the character.

Caveats & Gotchas

  • The gravity direction must be kept in sync between autonomous proxy and authority yourself — the engine corrects it as part of normal movement corrections if it diverges, which can cause visible snapping if set inconsistently across the network.
  • Passing a zero or near-zero vector fails an internal ensure() and is silently ignored, leaving the previous gravity direction unchanged.
  • bHasCustomGravity is only refreshed here by comparing against DefaultGravityDirection, so HasCustomGravity() won't reflect a change until this function has actually run.

Signature

virtual void SetGravityDirection(const FVector& GravityDir)

Parameters

Name Type Description Default
GravityDir const FVector& A non-zero vector representing the new gravity direction. Normalized internally.

Return Type

void

Example

Walk on the inside of a spherical room C++
const FVector ToCenter = (SphereCenter - GetActorLocation()).GetSafeNormal();
GetCharacterMovement()->SetGravityDirection(-ToCenter);

Version History

Introduced in: 5.4

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.