RealDocs

APawn::GetMovementComponent

function Engine Blueprint Since 4.0
#include "GameFramework/Pawn.h"
Access: public Specifiers: virtualUFUNCTIONBlueprintCallable

Description

Returns the pawn's movement component, if it has one. The default implementation scans all components for the first UPawnMovementComponent; native subclasses should override this for efficiency.

Caveats & Gotchas

  • The base APawn implementation iterates all components each call, which is O(n). If you call this frequently (e.g., every tick), override it in your subclass to return a cached pointer instead.
  • Returns nullptr for Pawns that have no movement component — always null-check the result before calling methods on it.
  • ACharacter caches its CharacterMovementComponent and overrides this function, so the base scan only happens for custom APawn subclasses that forget to override.

Signature

virtual UPawnMovementComponent* GetMovementComponent() const

Return Type

UPawnMovementComponent*

Examples

Cast movement component to CharacterMovementComponent and set max walk speed Blueprint
Event BeginPlay Get Movement Component Target is Pawn Target Return Value Cast To CharacterMovementComponent Object Cast Failed As Character Movement Component As Character Movement Component Max Walk Speed Target is Character Movement Component Target Max Walk Speed 600.0 600.0 Max Walk Speed
Edit Blueprint graph Cast movement component to CharacterMovementComponent and set max walk speed
Drag node headers to move · Drag from an output pin to an input pin to connect · Scroll to zoom · Right-click for actions
Check velocity cap before adding input C++
void AMyPawn::Tick(float DeltaTime)
{
	Super::Tick(DeltaTime);
	if (UPawnMovementComponent* MoveComp = GetMovementComponent())
	{
		if (MoveComp->Velocity.SizeSquared() < MaxSpeedSq)
		{
			AddMovementInput(GetActorForwardVector());
		}
	}
}

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.