Download

How do disable a key for a second and then reactivate it after? c++

Good afternoon,
I cant seem to find this anywhere online. I have perfected how my roll works in my game. I have anim notifies in my animation and I’d like to disable the space bar / action mapping for until a certain part of the animation. Disable input disables my entire keyboard as well as my mouse which isnt something I want. Can anyone help or direct me to a solution? Thank you.

So for example: You have a semi auto pistol, you cant hold down the trigger for the pistol. You must lift and re-execute the command to shoot to the pistol again.

I don’t know if what you are looking for is possible in the way you describe.

What you could of course do is have the logic that runs after pressing the spacebar to be guarded by a boolean that you set to true/false with your animation notifies.

hmmm some sort of like, “is currently dodging”?

Yes, even though I personally don’t like using “Is” in my booleans as that is already implied in my opinion

I got it working! I can hold roll but it wont execute until the anim notify has been executed and the bool is true to roll again. Its not EXACTLY how I wanted it but it works as intended!

Eventually you’re going to have so many of these booleans.
Then you will do “if A and B and C and D and and and…”

Yea.
Is this normal or is there a better design?

I use “state machines” on gameplay blueprint instead.
Depending on which state is active, pressing spacebar will do nothing because there’s no code running that could process the spacebar input at that state graph.

In more complex situations I would get current gameplay state then do a “Switch on myStates” in anim bp to gate where update tick should go.

You can turn off a key, but the cost for the operation is not really efficient,
The good design is a people say here, boolean.

By the way, there is a design common mistake :
Don’t do “CanFire” boolean, like if you are stopping sprinting and you don’t want people fire while sprinting, like :

I Start sprint -> Set CanFire to false.
I Stop Sprint -> Set CanFire to true.

Always use "IsSprinting Instead, and check in fire fonction, if we are sprinting, or not.
Setup state, and not possibility, this with avoid a lot of design probleme cause with possibility, multiple function (sprint, jump) can touch to the boolean, and it will be a hell to handle.

Thx for the tip that makes sense ! (I did this mistake, ahah! Refactor time)

I’ll definetly check your state machines tool which is at a fair rate :slight_smile:

Yeah i did this mistake too on my early project :wink:

So i assum it’s pretty common.