Left Shift not making character sprint c++

I’m trying to make it so that the character in my game is able to sprint by holding the left shift key. However, currently when I hold down the left shift key my character’s speed doesn’t change at all.

I’ve added the action mapping to the project setting for the left shift key.

I’ve mapped the action on both IE_Pressed and IE_Released in my SetupPlayerInputComponent function:

InputComponent->BindAction("Sprint", EInputEvent::IE_Pressed, this, &APlayerCharacter::OnStartSprint);
InputComponent->BindAction("Sprint", EInputEvent::IE_Released, this, &APlayerCharacter::OnStopSprint);

The functions being bound for the input event are:

void APlayerCharacter::OnStartSprint()
{
	bPressedSprint = true;
}

void APlayerCharacter::OnStopSprint()
{
	bPressedSprint = false;
}

And my functions for handling movement are set up like so:

 void APlayerCharacter::MoveFrontBack(float Value)
 {
 	if (Controller && Value != 0.0f)
 	{
 		FRotator Rotation = GetActorRotation();
 
 		if (GetCharacterMovement()->IsMovingOnGround() || GetCharacterMovement()->IsFalling())
 		{
 			Rotation.Pitch = 0.0f;
 		}
 
 		FVector const Direction = FRotationMatrix(Rotation).GetScaledAxis(EAxis::X);

		if (bPressedSprint) Value *= SprintModifier;

 		AddMovementInput(Direction, Value);
 	}
 }
 
 void APlayerCharacter::MoveLeftRight(float Value)
 {
 	if (Controller && Value != 0.0f)
 	{
 		FRotator const Rotation = GetActorRotation();
 		FVector const Direction = FRotationMatrix(Rotation).GetScaledAxis(EAxis::Y);

		if (bPressedSprint) Value *= SprintModifier;

 		AddMovementInput(Direction, Value);
 	}
 }

The SprintModifier and bPressedSprint variables are also declared in my header file:

private:
	bool bPressedSprint = false;
	float SprintModifier = 2.0f;

Am I missing something obvious here as to why my character’s speed does not increase when holding down the left shift key?

Try to modify max walk speed

//
float InitialSpeed;

// Begin Play
InitialSpeed = MovementComponent->GetMaxSpeed();

//
MovementComponent->MaxWalkSpeed = InitialSpeed * 2.0;

MovementComponent is an undeclared identifier.

However I can get the MovementComponent via GetMovementComponent().

Now, the problem is that it seems my MovementComponent is of the UPawnMovementComponent type and doesn’t have the MaxWalkSpeed variable.

Fixed the problem.

First, I declared a new variable in my Character class called DefaultMaxWalkingSpeed and set it equal to GetCharacterMovement()->MaxWalkSpeed in my BeginPlay function:

//APlayerCharacter.h
private:
    float DefaultMaxWalkingSpeed = 0.0f;

//APlayerCharacter.cpp -> BeginPlay()
DefaultMaxWalkingSpeed = GetCharacterMovement()->MaxWalkSpeed;

Then in my OnStartSprint and OnStopSprint functions I added a line of code to change the MaxWalkSpeed of the CharacterMovement component to their respective values:

void APlayerCharacter::OnStartSprint()
{
	bPressedSprint = true;
	GetCharacterMovement()->MaxWalkSpeed = DefaultMaxWalkingSpeed * SprintModifier + SpeedModifier;
}

void APlayerCharacter::OnStopSprint()
{
	bPressedSprint = false;
	GetCharacterMovement()->MaxWalkSpeed = DefaultMaxWalkingSpeed + SpeedModifier;
}

I also removed these lines from my movement functions:

if (bPressedSprint) Value *= SprintModifier;

Cast(GetMovementComponent())