Can't get my sprint function working

Hello forums, so I have a small issue. I’ve googled around a fair bit and not really found a solution. In my project, I decided to code a simple sprint function activated when the user presses left shift.

The code is literally:


void AFRCharacter::OnStartSprint()
{
	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("I got the call!"));
	GetCharacterMovement()->MaxWalkSpeed = 2000.0f;
}

void AFRCharacter::OnStopSprint()
{
	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Me too!"));
	GetCharacterMovement()->MaxWalkSpeed = 500.0f;
}

The issue: I get my confirmation debug messages, but my speed doesn’t change. Since my debug messages write when they’re supposed to (when L.Shift is pressed or released, respectively), I’ve ruled out any issues outside my FRCharacter class… Which is constructed just like the one in the FPS tutorial. In fact, during the FPS tutorial, I wrote this same code (and it worked) and then implemented a stamina system around it.

Any ideas?

Have you checked whether these values are being overwritten in the editor?
If there is a blueprint of the character, the MaxWalkSpeed might get overwritten.

I’m setting my pawn class like this, in my custom gamemode, FRGameMode:


DefaultPawnClass = AFRCharacter::StaticClass();

And I have set the Editor to use FRGameMode in preferences. I do have a blueprint of FRCharacter though, could this still cause issues?

If you are getting the debug messages, then at least you know the code is being called. My guess is that MaxWalkSpeed is not the variable that you need to set. Have you verified that changing that variable works?

I believe that the blueprint’s defaults values will overwrite the code’s.

Are you sure you want to be adjusting the walk speed, and not moving the character into a ‘running/sprinting’ state?

Well, from what I could find, MaxWalkSpeed is what determines the character’s maximum speed, and currently I’d just like him to move faster when L.Shift is held down.

I’ve tried deleting the FRCharacter_BP, recreating the FRCharacter_BP and declaring it the primary pawn class like this:


static ConstructorHelpers::FClassFinder<APawn> PlayerPawnObject(TEXT("Blueprint'/Game/John/FRCharacter_BP.FRCharacter_BP_C'"));
	if (PlayerPawnObject.Class != NULL)
	{
		DefaultPawnClass = PlayerPawnObject.Class;
	}

and, setting my capsule component as my root component, nothing worked. Currently, MaxWalkSpeed refuses to change during runtime (on exclusively this project) through C++, but I can alter the BP and it actually changes, but then won’t change dynamically in game (will try BP scripting the change next).

Hmmm, changed project, transferred assets, and tada! it works… Sorry guys, no definitive answer but I’m good to go. Thanks for the help anyway!