Timer issue: avoid delay on first mouse click?

Dear experts,

I set up a fire function when I click the left mouse button. I have a delay of 2 seconds. But when I click the first time the delay already kicks in. But I don’t want that:

void ATurret::StartFire()
FTimerDelegate TimeDelegate;
TimeDelegate.BindUFunction(this, FName("FireProjectile"), Fire1MissileClass);
GetWorldTimerManager().SetTimer(FiringTimerHandle, TimeDelegate, 2.0f, false);

What am I missing? How can I avoid the delay on the first click?

Thank you, Peter

Missing another parameter (float InFirstDelay) https://docs.unrealengine.com/en-US/…ger/index.html :

GetWorldTimerManager().SetTimer(FiringTimerHandle, TimeDelegate, 2.0f, false, **0.0f**);

or you can call the function after setting the timer.

Hi EvilCleric,

I could not get this to work with the timer. I made my own method finally.

In the .h file

 /* time between shots **/
UPROPERTY(EditAnywhere, BlueprintReadWrite,Category = "Projectile")
float FirePause;

/* last time fired **/
float LastFireTime;

In the .cpp file

void ATurret::StartFire(float DeltaTime)
  float CurrentSeconds = DeltaTime;

/* if we want to fire quickly again and the current time is smaller
than last fire time + fire pause time we just return **/
if (CurrentSeconds < LastFireTime) { return; }
   LastFireTime = CurrentSeconds;
/* we add the fire pause to the time fired **/
   LastFireTime += FirePause;

best regards, Peter