WASD Movement: undestanding MoveForward code

Hi, I’m trying to learn UE coding and started with the FPS Tutorial.

I’m stuck to understand why in this code you need to check the pitch and set it to 0.0f:

 void AFPSCharacter::MoveForward(float Value)
    {
        if ( (Controller != NULL) && (Value != 0.0f) )
        {
            // find out which way is forward
            FRotator Rotation = Controller->GetControlRotation();
            // Limit pitch when walking or falling
            if (GetCharacterMovement()->IsMovingOnGround() || GetCharacterMovement()->IsFalling() )
            {
                Rotation.Pitch = 0.0f;
            }
            // add movement in that direction
            const FVector Direction = FRotationMatrix(Rotation).GetScaledAxis(EAxis::X);
            AddMovementInput(Direction, Value);
        }
    }

Isn’t the pitch involve the Y axis while I’m extracting from the rotation matrix the X info into a vector?
When I go to extract the Y instead I don’t check anything:

 void AFPSCharacter::MoveRight(float Value)
    {
        if ( (Controller != NULL) && (Value != 0.0f) )
        {
            // find out which way is right
            const FRotator Rotation = Controller->GetControlRotation();
            const FVector Direction = FRotationMatrix(Rotation).GetScaledAxis(EAxis::Y);
            // add movement in that direction
            AddMovementInput(Direction, Value);
        }
    }

In the FPS template the GetActorForwardVector() is used instead of the above code, can I assume this function does the same.

The way the move code works is that it doesn’t assume that when you walk forward you will walk perpendicular to gravity. So if you are in water and Pitch is not 0, then you are either moving slightly up or down (swimming). But when you are on ground your character’s up vector should always be parallel to gravity (or else your character’s capsule will be leaning backwards or forwards). So they’re forcing your pitch to zero in order to guarantee you don’t start walking off into space while on the ground if your character is slightly pitched. Obviously you won’t actually walk off the ground even if you’re pitched because of gravity, but your movement won’t be consistent with that where pitch is 0. So setting pitch to zero is about keeping consistency in movement when on the ground or falling.