Set Timer Handlers

Hey Everyone!

I’m trying to work on a simple buck shot firing mechanism, with slight offsets using timers.
The only problem is each handler is overwriting the last,

I’m doing it like so:

GetWorldTimerManager().SetTimer(this, &ABoBaChar::ActuallyFire, 1, false, 0.1f);
GetWorldTimerManager().SetTimer(this, &ABoBaChar::ActuallyFire, 1, false, 0.2f);
GetWorldTimerManager().SetTimer(this, &ABoBaChar::ActuallyFire, 1, false, 0.3f);

I’ve also tried:

GetWorldTimerManager().SetTimer(this, &ABoBaChar::ActuallyFire, 0.1f, false);
GetWorldTimerManager().SetTimer(this, &ABoBaChar::ActuallyFire, 0.3f, false);
GetWorldTimerManager().SetTimer(this, &ABoBaChar::ActuallyFire, 0.5f, false);

But I just can’t seem to get it to work.
Any ideas? As I’m not sure on how the function actually works.
(Starting to miss the one from UE3)

Thanks guys!

-Peace

You Need to use version with Handle

FTimerHandle MyHandle;


IntervalTimer.SetTimer(MyHandle, IntervalDelegate, ProjectileInfo.Interval, true, 0);

Looking at the code in FTimerManager, you can only have one outstanding timer to a given function using the API that you are calling, so the subsequent calls to create the timer are overwriting previous timers. The way to get around that is to manually create unique FTimerHandle objects. Your code would then look like:

GetWorldTimerManager().SetTimer(TimerHandle1, this, &ABoBaChar::ActuallyFire, 1, false, 0.1f);
GetWorldTimerManager().SetTimer(TimerHandle2, this, &ABoBaChar::ActuallyFire, 1, false, 0.2f);
GetWorldTimerManager().SetTimer(TimerHandle3, this, &ABoBaChar::ActuallyFire, 1, false, 0.3f);

Thank you!
This is exactly what I needed!

I had assumed that the function names where used as handlers…
Woops!

I’ll just add a little more detail. The delegate code doesn’t take into account any var args when doing the comparison for “is this the same delegate” underneath the hood.

This will bite you in other places as well, where equality of delegates matter.

Will this make 3 instance of the timer which will be triggered at 1.1, 1.2 and 1.3 seconds delay?

watch this