Loken01_1
(NoelWatters)
August 13, 2014, 9:58pm
1
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
iniside
(iniside)
August 13, 2014, 10:22pm
2
You Need to use version with Handle
FTimerHandle MyHandle;
IntervalTimer.SetTimer(MyHandle, IntervalDelegate, ProjectileInfo.Interval, true, 0);
joeGraf
(joeGraf)
August 13, 2014, 10:42pm
3
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);
Loken01_1
(NoelWatters)
August 14, 2014, 12:02am
4
Thank you!
This is exactly what I needed!
I had assumed that the function names where used as handlers…
Woops!
Crzyhomer
(Crzyhomer)
August 14, 2014, 6:02pm
5
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.
envenger
(envenger)
April 1, 2015, 8:27am
6
Will this make 3 instance of the timer which will be triggered at 1.1, 1.2 and 1.3 seconds delay?