Input listening Timer

Hi There,

I basically have a character who arms himself when the attack button is pushed the first time. What I am looking to do is have him automatically sheath his weapon after an amount of time if the player hasn’t pressed the attack input (For example, 10 seconds after no input). I am trying to avoid using tick, since I am trying to keep my project as lean as possible. Any tips on how I could get this done?

Thanks in advance!

You can easily do this with tick, but if not an option you can spawn an actor that handle this for you.

  1. Create one Int variable call (launchAttack) in your character;
  2. Create an actor call (attackTimer) and a custom event call (start) with one Int variable & (your actor) variable;

  1. Each time user attack increment your variable (launchAttack), spawn actor from class (attackTimer) and execute the custom event (start) with the (launchAttack) Int and a self reference.

So you can see a basic example on how you can do that. Basically, this spawn your actor, wait 10 seconds, with the last attack number and then test the variable with the actual variable in your character. After all process, failed or success, you need to destroy the actor because you don’t need them anymore and you don’t want the user to spawn 10 000 actor.

This is very light and you could improve it. Just keep a list of all actor in an array and we know that if the object still alive, it means that the 10 seconds is not over so you can destroy it if an attack is launch again and so you are sure to always have only one actor.

Hope that can help you, let me know if you need more explanation! have good day.

Hello Zerif,

Does something like this work for you? (Timer be reset every time LMB is pressed)

Can we be sure that this timer be reset if it’s launch a micro second before ?

Use a retriggereable delay. After your attack or the input for the attack call an event to sheath the weapon. this sheath wep event would have a retriggerable delay then the script to actually fire the animation. The retriggerable delay reset the delay time every time its activated, so say your delay is 10 seconds and after five seconds the attack button is pressed for the second time the delay would reset its duration back to 10 seconds and start counting down again.