Why don't timers start immediately?

If I start a looping timer using Set Timer by Event or Set Timer by Function Name, the first “tick” of the timer only happens after the Time value. Why?

The tooltip on Time reads, “How long to wait before the delegate, in seconds.” However, why doesn’t the first tick occur immediately and then every Time seconds after that.

I’m trying to use a timer to spawn a bullet every 2 seconds while the mouse button is held down. The problem is that because the first tick of the timer doesn’t happen until after 2 seconds, it means that it takes 2 seconds before the player sees their first bullet spawn after they hold the mouse button down. Very annoying. Is there another way to do this, or a way to force a timer to tick immediately upon start?

Call the function you are setting the timer for right before setting the timer. This will cause it to fire immediately, and then for every 2 seconds after that. Would also want to put in some sort of do-once to block from firing that initial node over and over again, if the player were to repeatedly press and release the button, for example.

I know this is 10 years old, but since this is unanswered and the first result when searching it, here is the correct answer:

I don’t know since when, but there is an optional parameter InFirstDelay now on the SetTimer function:

void SetTimer(FTimerHandle& InOutHandle, FTimerDelegate const& InDelegate, float InRate, bool InbLoop, float InFirstDelay);

By default it is set at -1, and when it is < 0.f, it uses InRate time for the first loop. So you just have to do something like this:

FTimerHandle BulletTimerHandle;

GetWorldTimerManager().SetTimer(BulletTimerHandle, this, &AMyPlayerController::FireBullet, 2.f, true, 0);

With this, the function FireBullet will trigger immediately, and then every 2 seconds.