RealDocs

ACharacter::GetMovementComponent

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

Description

Returns the movement component for this character as a UPawnMovementComponent pointer. For ACharacter, this is always the UCharacterMovementComponent unless the class has been customized.

Caveats & Gotchas

  • Returns a UPawnMovementComponent* — cast to UCharacterMovementComponent* if you need character-specific API. Prefer the typed GetCharacterMovement() accessor instead, which avoids the cast.
  • Can return nullptr if the component was not created (e.g. you called DoNotCreateDefaultSubobject in your constructor).

Signature

virtual UPawnMovementComponent* GetMovementComponent() const override

Return Type

UPawnMovementComponent*

Example

Access movement component via base interface C++
// Generic code that works on any APawn:
UPawnMovementComponent* MoveComp = GetMovementComponent();
if (MoveComp)
{
    MoveComp->StopMovementImmediately();
}

// For ACharacter-specific API, prefer:
GetCharacterMovement()->SetMovementMode(MOVE_Flying);

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.