ACharacter::GetCharacterMovement
#include "GameFramework/Character.h"
Access: public
Specifiers: UFUNCTIONBlueprintCallable
Description
Returns the CharacterMovementComponent attached to this character. Use this to read or set movement parameters like MaxWalkSpeed, JumpZVelocity, GravityScale, and movement mode at runtime.
Signature
UCharacterMovementComponent* GetCharacterMovement() const Return Type
UCharacterMovementComponent* Caveats & Gotchas
- • Can return null if the character was constructed without a CharacterMovementComponent. In standard subclasses this is never null, but always guard when working with custom subclasses.
- • If you have replaced the default movement component with a custom subclass, cast the result to your subclass type before accessing custom properties.
- • Avoid caching the pointer across frames in multiplayer — the component is always present after BeginPlay, but accessing it before BeginPlay (e.g. in the constructor) is only safe via CreateDefaultSubobject.
Example
Modifying movement speed at runtime C++
if (UCharacterMovementComponent* Move = GetCharacterMovement())
{
Move->MaxWalkSpeed = bIsSprinting ? 900.f : 600.f;
} Tags
Version History
Introduced in: 4.0
| Version | Status | Notes |
|---|---|---|
| 5.6 | stable | — |
Feedback
Was this helpful?