Download

Simple ClearTimer Problem

Hey, first post here. I held out as long as I could haha.

I have a background in scripting, but I’m just now delving into C++, so syntax and more complex concepts like casting are still tricky for me. Right now I’m having trouble testing out a very basic timer function to initially set the max walking speed to zero (which works fine) and then reset it to the default of 600 once the timer goes off (which also works fine). However, I want the timer to also be able to be cleared/cancelled under certain circumstances. That isn’t working.

void ASCharacter::BeginPlay()
{
Super::BeginPlay();

GetCharacterMovement()->MaxWalkSpeed = 0;

FTimerHandle TimerHandle_AllowMove;
GetWorldTimerManager().SetTimer(TimerHandle_AllowMove, this, &ASCharacter::AllowMove, 3.0f);
}

// Cancel the timer before it expires

void ASCharacter::BeginCrouch()
{
Crouch();

//** Test if timer clear works
GetWorldTimerManager().ClearTimer(TimerHandle_AllowMove);
}

I know the Crouch function itself works fine. I’ve slipped in debugging notes in place of the ClearTimer and they all run fine. Am I missing something? I’ve included the TimerManager.h. Any ideas? I’ve tried PauseTimer, and I’ve tried setting the timer again with a negative value. Also, how many instances of a timer can run at once? Just one or multiple? Thanks!