How to hit button a few times before event starts in blueprint

I would like to enable “set enable gravity” function after I pushed the same button at the keyboard for 10times.

Hello,
that should be quite easy to accomplish.

  • you will need a variable to store the number of keyboard hits
  • every time you hit the keyboard key add 1 to value of your counter
  • when it reaches 10, change gravity
  • reset counter value after it reached 10

Something like this (added extra key so you can toggle it for testing)

Maybe this will help you, it’s all been done inside Character Blueprint.

The above setup should work for you. You can create a variable inside your desired blueprint and just use the code I’ve provided above. Try adding it after you have performed a Key check, when true add to your variable, then perform another check if it has reached value you desire.

In your example you are setting the collision but earlier you mentioned you want to set gravity. This is a bit confusing to me, maybe you can clarify. I mean what is the concept here, try to dumb it down as much as you can. :slight_smile:

I think you should try, if possible, moving the code to your character. Whenever I watch a tutorial people always say you shouldn’t use tick event is you don’t have to. Checking every frame if F was pressed doesn’t seem like a good idea, you only want to run this when you actually do something.

If I’m wrong about this please correct me.

thanks for your quick help,
it doesn’t quite work in my setup.
I am not in a characer blueprint. It is a blueprint attached to a static mesh actor.
In the attached screenshot you can see my basic setup. This works as soon I’ve pressed the “F” key once.
But, I don’t know how to add the counter in this case.

thanks

ok thanks, I did it in the level blueprint and used a reference to the specific mesh. And it works fine now. Many thanks!
Now, I am looking for a delay, so I am only able to press the key once every minute and not more within this time. is this possible as well?

That’s great news!

You will need a bool variable and a branch just after your action key fires off.
Default will be false so you can use your skill/action when the game starts and when you finish running your code you will set that variable to true. Next time you press the key, you won’t be able to use it. After that setter you just run your delay, then reset the bool to false by using another setter.

I tried to write this in a simple way and as clear as possible, but let me know if something isn’t clear enough.

You might want to check the link below:

thanks for the link, not sure if I understand it. Would it be possible to send a screenshot of a blueprint?
many thanks

Hey there.

It would be best if you could show of some of your code in order to get it setup properly. I have made similar thing as above, maybe it will help you out.

So your bool variable is getting set to true when you fire off your event, when the clock (custom event) starts. Once it reaches it’s maximum value it will re-enable (reset the bool to default) usage of your event and set the time to 0.
Bear in mind that this is a very basic setup, but you don’t want to over complicate things too much.