MaxWalkSpeed changes not properly effecting characters

Omfgabrandon
Wed, 09 Apr 2025 18:47:11 +0000
Programming & Scripting

i’m attempting to add a simple sprint feature to my multiplayer game, but the behavior I get is very strange. In its current state, the character will adjust its animation as if its speed has changed, but the speed itself remains the same regardless of the sprint state.

		EnhancedInputComponent->BindAction(SprintAction, ETriggerEvent::Started, this, &ANoSanctuaryCharacter::Sprint);
		EnhancedInputComponent->BindAction(SprintAction, ETriggerEvent::Completed, this, &ANoSanctuaryCharacter::StopSprint);

void ANoSanctuaryCharacter::Sprint()
{
	UE_LOG(LogTemp, Error, TEXT("Setting max walk speed to %f on client"), GetCharacterMovement()->MaxWalkSpeed);
	ServerSprint(true);
}

void ANoSanctuaryCharacter::StopSprint()
{
	GetCharacterMovement()->MaxWalkSpeed = WalkSpeed;
	UE_LOG(LogTemp, Error, TEXT("Setting max walk speed to %f on client"), GetCharacterMovement()->MaxWalkSpeed);
	ServerSprint(false);
}

void ANoSanctuaryCharacter::ServerSprint_Implementation(bool Sprinting)
{
	if (Sprinting) {
		UE_LOG(LogTemp, Error, TEXT("Server sprinting true"));
		GetCharacterMovement()->MaxWalkSpeed = SprintSpeed;
		GetCharacterMovement()->MaxCustomMovementSpeed = SprintSpeed;
		UE_LOG(LogTemp, Error, TEXT("Setting max walk speed to %f on server"), GetCharacterMovement()->MaxWalkSpeed);
	}
	else {
		UE_LOG(LogTemp, Error, TEXT("Server sprinting false"));
		GetCharacterMovement()->MaxWalkSpeed = WalkSpeed;
		GetCharacterMovement()->MaxCustomMovementSpeed = SprintSpeed;
		UE_LOG(LogTemp, Error, TEXT("Setting max walk speed to %f on server"), GetCharacterMovement()->MaxWalkSpeed);
	}

	SprintOnClient(Sprinting);
}

void ANoSanctuaryCharacter::SprintOnClient_Implementation(bool Sprinting)
{
	if (Sprinting) {
		GetCharacterMovement()->MaxWalkSpeed = SprintSpeed;
		UE_LOG(LogTemp, Error, TEXT("Setting max walk speed to %f on client"), GetCharacterMovement()->MaxWalkSpeed);
	}
	else {
		GetCharacterMovement()->MaxWalkSpeed = WalkSpeed;
		UE_LOG(LogTemp, Error, TEXT("Setting max walk speed to %f on client"), GetCharacterMovement()->MaxWalkSpeed);
	}
}

For a single tick it will register these changes, then on the server it reverts to its default setting of 600.

LogTemp: Error: Server sprinting true
LogTemp: Error: Setting max walk speed to 10000.000000 on server
LogTemp: Error: Setting max walk speed to 10000.000000 on client
LogBlueprintUserMessages: [BP_Player_C_0] Server: Max Speed: 10000.0
LogBlueprintUserMessages: [BP_Player_C_0] Server: Max Custom Movement Speed:  10000.0
LogTemp: Error: Setting max walk speed to 10000.000000 on client
LogBlueprintUserMessages: [BP_Player_C_0] Client 1: Max Speed: 10000.0
LogBlueprintUserMessages: [BP_Player_C_0] Client 1: Max Custom Movement Speed:  10000.0
LogBlueprintUserMessages: [BP_Player_C_0] Server: Max Speed: 600.0
LogBlueprintUserMessages: [BP_Player_C_0] Server: Max Custom Movement Speed:  10000.0
LogBlueprintUserMessages: [BP_Player_C_0] Client 1: Max Speed: 10000.0
LogBlueprintUserMessages: [BP_Player_C_0] Client 1: Max Custom Movement Speed:  10000.0
LogBlueprintUserMessages: [BP_Player_C_0] Server: Max Speed: 600.0
LogBlueprintUserMessages: [BP_Player_C_0] Server: Max Custom Movement Speed:  10000.0

The only thing I could think of is it somehow being set somewhere else in the code, but my project has no other place this is set so I’m thinking maybe there is some kind of safety mechanism built in somewhere that will revert this that I’m unaware of?

2 posts - 1 participant