RealDocs

ACharacter::GetCharacterMovement

function Engine Since 4.0
#include "GameFramework/Character.h"
Access: public Specifiers: inlineconst

Description

Returns the character's `UCharacterMovementComponent`. This is the primary accessor for adjusting movement parameters such as speed, gravity, and movement mode at runtime.

Caveats & Gotchas

  • A templated overload `GetCharacterMovement<T>()` exists for subclasses that replace the default movement component with a custom type. Use that form when working with a custom movement component to avoid a manual cast.
  • The pointer is set during construction via `CreateDefaultSubobject` and is never null in a properly constructed character. However, if you call this from a constructor before `PostInitializeComponents`, dependent subsystems may not yet be initialized.
  • Calling movement-modifying methods (e.g. `AddForce`, `SetMovementMode`) on the returned component from a simulated proxy will have no lasting effect — movement authority resides on the server or autonomous proxy.

Signature

inline UCharacterMovementComponent* GetCharacterMovement() const { return CharacterMovement; }

Return Type

UCharacterMovementComponent*

Examples

Adjust max walk speed at runtime C++
void AMyCharacter::ApplySprint(bool bSprinting)
{
	if (UCharacterMovementComponent* CMC = GetCharacterMovement())
	{
		CMC->MaxWalkSpeed = bSprinting ? 900.f : 600.f;
	}
}
Access a custom movement component subclass C++
// Using the templated form to avoid a manual cast
if (UMyMovementComponent* CMC = GetCharacterMovement<UMyMovementComponent>())
{
	CMC->MyCustomProperty = 42.f;
}

Version History

Introduced in: 4.0

Version Status Notes
5.6 stable

Feedback

Was this helpful?

Suggest an edit

Select a field above to begin editing.