How to lock a key for a certain amount of time?


I have a Dash function which can be used by pressing the SpaceBar, I have a Bar that will go empty and refill so you can dash again. the problem is that if you press the key again, the bar will empty again and it will glitch. Is there a way to lock the spacebar for 3 seconds?

This is my Current Blueprints

Dash Bar

Here is the Dash Function

Any Help will be deeply appreciated!!

P.S. the many copies of Set Percent was because the Progress Bar fills from 0.0 being empty to 1.0 to being full, so i couldn’t figure out how to get a timer running and fill the bar in 2 seconds, i came up with this, which sorta works, but yeah… :smiley:

Hey there, this is a way too complicated setup for what you want to achieve. Have a look at the DoOnce or Do N inputs. They are basically nodes that only function a certain number of times. E.g. if you want to dash, you put a DoOnce node after the Dash Input node. It won’t fire after the first time until you reset that node. To reset it you can just use a custom event that fires once the dash is complete.

DoOnce is useful for dash-like events. Do N is useful for double-tap events like double jump or the dash in UT2004 (double pressing any movement key would make your character dash in that direction).

Here is a sample:


Even though @alperenakyuz solution will work perfectly let me give you another way you could do this:

Since you can “Set Percet” there has to be a “Get Percent” as well so you can use that to check if it’s 100 or not.

If you press the spacebar empty it to 0 percent.

Also I would recommend not doing the the refill bar like you have (you probably figured that this is a bit messy) but rather use the “Delta Time” variable.

This variable will provide you with how many seconds have passed since the last tick (usually something like 0.0something). You can use this to multiply the delta time by the rate at which you want it to refill per second and it will give the the result you’re looking for.

You can then also check if the bar is full and as long as it isn’t add the value and all of this with under 7 nodes!

Just a very minor thing to remember. Check if it’s going over 100%. If so just set it to 100 and it should not do anything else. I’m not entirely sure what happens if you go over 100%… it might just extend the bar further.

I know the dash bar is a bit too messy, is just that i haven’t found how exactly to achieve it. Now, you’re onto something, i would multiply the delta time for each dash time to record that time?? I’m a bit confused. The Bar does fill when you reach 1.0. the idea of the dash is to give 2 seconds of cooling off. i locked the dash function for 2 seconds, if you press it, the bar goes to 0.0 (the begging of the dash cool-off), then somewhat gradually using delays reach to 1.0 by adding fractions of a float such as .23 after .05, fill .54 and so on.Back to the subject how would you express the 7 nodes in Blueprints? keep in mind that the UMG Functions can’t use any tick events. So far, that’s been my experience.

I tried the reset code, but it keeps restarting the code. it doesn’t entirely work.

Oh, no wait, the DoOnce is where the Dash function is, sorry my bad! :smiley:

UMG is not a replacement for your HUD.

You can’t just use your UMG class as HUD and you shouldn’t. Usually you would use several once for the specific job they do (Menu, ingame menu, HP and other player stats, Gamemode stats (for example points of your team), etc.).

So you can just call a function inside of your UMG from your HUD each tick which updates your bar if it is not already full.