Can´t modify variable: Exception thrown: write access violation.

My code compiles, but as soon as I try to call this function in the game, I get this error:

Exception thrown: write access violation.
** that ** was nullptr.

function:

void UBasePawnMovement::SetMaxSpeed(float value)
{
MaxSpeed = value;
}

Both MaxSpeed and SetMaxSpeed() are public.
The function is in a CustomMovementComponent derived from FloatingPawnMovement.

How do I solve this problem?