Why does my server not allow MaxWalkSpeed to change on client?

When I set the MaxWalkSpeed of the player character on the client when the character presses the sprint input action, the server does not let the character walk faster. Initially I had thought that the client simply wasn’t able to receive a sprint input action because the client character wasn’t sprinting when the action was pressed. What I believe is happening now is that the client is in fact trying to sprint but the server is moving the client back because it doesn’t agree that the MaxWalkSpeed has changed.

When I showdebug enhancedinput in the console I see the enhanced input box jitter back and forth only when I press the sprint button, which further implies that the client is moving faster but then is getting moved back by the server. My sprint input action looks like:

void APlayerCharacter::sprintInput(const FInputActionValue& value) {

	APlayerController* localPlayer = Cast<APlayerController>(GetController());

	GEngine->AddOnScreenDebugMessage(-1, 2.0f, FColor::Yellow, FString::SanitizeFloat((float)GetRemoteRole()));

	
	if (value.Get<bool>()) {
		
		localPlayer->GetCharacter()->GetCharacterMovement()->MaxWalkSpeed *= 2.5f;
		//GetCharacterMovement()->MaxWalkSpeed *= 2.5f;
	}
	else {
		localPlayer->GetCharacter()->GetCharacterMovement()->MaxWalkSpeed /= 2.5f;

		//GetCharacterMovement()->MaxWalkSpeed /= 2.5f;
	}
	
	if (GetRemoteRole() == ROLE_Authority) {
		GEngine->AddOnScreenDebugMessage(-1, 2.0f, FColor::Green, FString::SanitizeFloat(localPlayer->GetCharacter()->GetCharacterMovement()->MaxWalkSpeed));
		
	}
}

bReplicates is set to true, and all other aspects of the movement replicate correctly, but the server does not seem to receive when the MaxWalkSpeed of the client changes. Sprinting works fine on the server. How do I get the server to recognize the change to MaxWalkSpeed?

To have the server recognize the change to MaxWalkSpeed, you need to use a network replication method. In your code, you can use the Multicast or Server functions to replicate the MaxWalkSpeed changes from the client to the server. For example:

void APlayerCharacter::sprintInput(const FInputActionValue& value) {
  APlayerController* localPlayer = Cast<APlayerController>(GetController());
  
  if (value.Get<bool>()) {
    localPlayer->GetCharacter()->GetCharacterMovement()->MaxWalkSpeed *= 2.5f;
    MulticastSprintStart();
  }
  else {
    localPlayer->GetCharacter()->GetCharacterMovement()->MaxWalkSpeed /= 2.5f;
    MulticastSprintEnd();
  }
}

void APlayerCharacter::MulticastSprintStart_Implementation() {
  GetCharacterMovement()->MaxWalkSpeed *= 2.5f;
}

void APlayerCharacter::MulticastSprintEnd_Implementation() {
  GetCharacterMovement()->MaxWalkSpeed /= 2.5f;
}

This way, when the sprint input is pressed on the client, the MulticastSprintStart function will be called, which will replicate the change to MaxWalkSpeed to the server and all other clients in the network. Similarly, when the sprint input is released, the MulticastSprintEnd function will be called, replicating the change to MaxWalkSpeed back to the original value.

I tried to implement those changes but I am getting “Failed to link patch” errors. The errors are saying that those functions are already defined in my PlayerCharacter.gen.cpp.obj.

In the header file I am doing:

UFUNCTION(Server, Reliable)
    void MulticastSprintStart_Implementation();

UFUNCTION(Server, Reliable)
    void MulticastSprintEnd_Implementation();

And in my cpp file I’m doing:

void APlayerCharacter::MulticastSprintStart_Implementation() {
	GetCharacterMovement()->MaxWalkSpeed *= 2.5f;
}

void APlayerCharacter::MulticastSprintEnd_Implementation() {
	GetCharacterMovement()->MaxWalkSpeed /= 2.5f;
}

The errors I am getting when compiling live coding say: