How to disable a specific key in Blueprint?

In my character blueprint I have it where the player can turn on and off a flashlight by using the “F” key. What I want to do is have my “F” key disabled at the start of my level and then enable it when I collect a flashlight. How would I do this? I have been looking for hours and trying everything I can think of but I can’t seem to find a straight answer. Can someone please show me an example blueprint if possible? Thanks!

Create a boolean variable on the character with a name like ‘enableFlashlight’. Set this variable to false when the player doesn’t have a flashlight and then set it to true when they collect the flashlight.

Then, on your key press event, do a ‘branch’ test for that boolean variable to see whether they should be allowed to turn on the flashlight. If they are, turn it on.

Is there any way that you can post a picture of what you told me? Sorry, I am just a bit lost on this one. I get what you are saying but I just can’t seem to visual see it. It would really help me out. Thanks!

How would this work when it comes to saving the state of the game? Would he have to do an inventory check on game load then? I’m assuming he wants to save the game, but if he doesn’t I’m curious to know myself.

@bigboy2k I would post a picture, but I’m not near a PC equipped with Unreal Engine and I won’t be for a few hours. If I find time tonight and you still need help I will work on a screenshot for you. :slight_smile:

I will try again to explain what I mean though. I’m assuming you’ve created the variable. Basically, whenever your character picks up the flash light, you want to ‘Get Player Character’ and connect that to ‘Set Enable Flashlight’ (or whatever the name of your variable is). Then, on your ‘F key press’ event, you want to connect a branch node. The boolean input for this branch node is the value of your Enable Flashlight variable. For this, you would need a ‘Get Enable Flashlight’ node. When your branch returns true, you can turn on the flashlight. When the branch returns false, just do nothing.

Hopefully that helps a little more.

That is a good point. I forget about that node more then I should.

Thanks Mellark and franktech for your help :slight_smile:

Unfortunately I still can’t get it to work :frowning:

Sometimes I am just more of a visual learner. Hopefully I can get some screenshots to help me with this. Thanks again!

Please, does anyone have a visual representation of what was explained above? I would really appreciate it as I am still lost on this one.

Maybe someone can also answer a question I am wondering about when it comes to this whole process. Why isn’t there a “disable input” for a specific key in blueprint? Wouldn’t that make this whole process so much easier?

Here’s a quick mockup I made:

You would still need a way to set the value of that boolean variable when you pick up the flash light, and obviously fill out the turn on and turn off flashlight events. Hopefully this helps :slight_smile:

Thanks Mellark! This really helped :slight_smile:

Not a problem! Glad I could be of assistance!