How can I stop a looping Timer?

Hi;

In C++ , I have a timer and I set it’s looping value to true :

...

GetWorldTimerManager().SetTimer(FTimerDelegate::CreateUObject(this, &AES_ScorBot::ObstacleTimerHandler), 5.0f, true);

....


void AES_ScorBot::ObstacleTimerHandler()
{
     if (!bHandleObstacle)
     {
          // HERE , I WOULD LIKE TO STOP THIS TIMER.....
     }
}

How can I stop this timer?

Thanks.

MSD

Save the FTimerDelegate you are creating, then it is as simple as:

GetWorldTimerManager().ClearTimer(YourFTimerDelegate);

You can even check if the timer is active and much more, look up documentation :).

Thanks BaderThanBad :
GetWorldTimerManager().ClearTimer( this, &AES_ScorBot::ObstacleTimerHandler);

Just a quick note, 4.7.1 now uses FTimerHandle instead of what you are doing now (FTimerDelegate) which is tagged as deprecated :).

FTimerHandle timer;
You can clear it using
GetWorldTimerManager().ClearTimer(timer)
Well ! thanks for asking :relaxed:

in current Unreal Engine > 5.1 we can use this:

GetWorld()->GetTimerManager().ClearTimer(LoadingTimerHandle);
2 Likes

Thanks! This effectively gives us the same functionality as the blueprint Clear and Invalidate Timer by Handle node.
In AActor derived classes we can use the short form:

GetWorldTimerManager().ClearTimer(Handle);