ClearTimer not stopping timer from running

In my game you can pickup speed powerups which increases the character’s movement speed for a set duration. I’m using a timer to reset the player’s movement speed after the set duration. If the player already has a speed powerup active and picks up another one, I would like to reset the timer.

Currently, when this occurs, I clear the timer and create a new one. The problem is that both of the timers still run even though I’ve cleared the first one.

My code below:

Try pulling the sprint timer handle out of the scope into the header as a uproperty and just reuse it. No need to constantly destroy and recreate it.
Personally I would do the same with the delegate and bind it in the constructor.

Then you could stop and reuse it at will without doing extra work in the function.

in stop sprint just use the handle to stop the timer

In appy pickup you would only need to set sprint to true and do a settimer (cleaner code)

SprintTimerHandle is already stored as a member on the header file. From what I understand the way to stop the timer is to run ClearTimer or am I mistaken?

Thanks for your comment regarding the delegate, that’s a good point.

The reason why I’m clearing the previous timer handle is because I want to cancel it and create a new timer handle. The situation is as follows: If the player picks up a speed powerup they can sprint for 5 seconds, if they pickup another one while sprinting, I want the sprinting “countdown” to reset to 5 seconds. So would help if I can either stop the timer and create a new one or restart the timer.