How to disable the "W" key using a bool?

Hi! I am trying to disable the “W” key when I enter a trigger. First, I created a bool variable in my player character. Then I added a pressed key “W” and connected it to a branch, followed by bringing in the bool variable and connecting it to the branch. I did make the bool variable set to true but where I get lost is that I am not sure what I am connecting to the True and False to disable the W. Also, is the bool variable and branch supposed to be created in he player controller instead?

Then in my level blueprint I have the Begin Overlap for my trigger, followed by Cast To my player character, and then have my Set bool connected to my Cast. Still nothing works works and I am completely lost as to why. Can anyone please help me by showing me an image(s) of what what they did to get something like this working? It would be greatly appreciated. Thank you!

1 Like

logically if you’re trying to disable it, it should be false. You could rename it from DontMove to CanMove. (not important but does make sense)

Off W dont set the bool, you’ve already done that in your trigger box, just run your logic (ie ApplyMove) off true (assuming its CanMove)

Am I doing it correct when I am using the Cast To in my level blueprints? Also, should I be doing this in my Character blueprint or should this be done in my Controller blueprint? I am bit confused by what you mean when you say “just run your logic”. Sorry for all the questions, I have been stuck on this for so long.

If anyone knows the easiest way to set this up using the First Person Blueprint with 5.6, that would be extremely helpful. Any images would also be helpful. Thank you!

Hi @bigboy2k ,
Do you want to disable the player’s forward movement when they enter the trigger, or do you have another function bound to the W key?

well by disabling W i assume you mean disable the logic that comes after W. So lets assume that is MoveForward. if you put MoveForward on the true path and Set CanMove to false then it wont fire.

I actually just want to know how to disable any key when entering a trigger but I am using “W” as an example because I do want to stop the player’s forward movement.

I have looked everywhere and I haven’t been able to find one solid example of how to do this or any video regarding how to disable a single key input during gameplay.

If (can Move) don’t process ‘W’ input, else allow movement

Thanks for the response. I understand what you are saying but I don’t know what that would look like in Blueprint. Do you have a way of showing me what that looks like? Thanks!

First of all what I recommend for testing all of this is to use Print Strings so you can see exactly when it’s being called.
To disable a key there isn’t a node that literally “turns it off.” What you’re really doing is disabling the logic that runs behind that input. You could do this with branches, but if you want a cleaner and more scalable solution, the recommended way is to use Input Mapping Contexts (IMC) in Enhanced Input
( Documentation : Enhanced Input in Unreal Engine | Unreal Engine 5.6 Documentation | Epic Developer Community).

The cleanest and most scalable way to disable a specific key (like W for forward) is through IMCs. What you do is duplicate your default IMC (for example, IMC_Default - IMC_DisableKey) and in that copy remove the binding for the action you want to disable. In this case, that would be the forward movement action bound to W.
(IMC Without specific key )


(IMC Default with all keys )

In your PlayerController, create two events:

  • DisableKeys: removes the default IMC and adds your custom IMC without the W binding.
  • EnableKeys: does the opposite, removes your custom IMC and re-adds the default one.

From the Level Blueprint (or from your Bluepint ), you simply call DisableKey Event when the player enters a trigger and EnableKeyEvent when they leave, or at any other point where you want to toggle the behavior.
(Blueprint with a trigger)

Level Blueprint

The advantage of doing it this way is that your gameplay logic stays clean and separated from input logic. Instead of filling your Blueprints with branches and condition checks, you just switch contexts. This also lets you create different “control profiles” and scale the system easily without conflicts.

In case you want to disable it using a Branch, here’s a link where they talk about the topic, so you can better understand how it works:

And I’m also leaving it set up with an example of how it works. In my case I used Disable Input and Enable Input

And lastly, in case you want to know where the movement logic is and how to disable moving forward and backward, I’m leaving you an example with a Select and an Enable/Disable Forward/Backward . This disables the forward and backward movement logic whenever the player overlaps with the trigger, and re-enables it when exiting the trigger.

Hope it helps!

Create a folder called Interfaces in your Content/FirstPerson/Blueprints directory.

In the Interfaces folder create a BP Interface class. Name it BPI_Pawn.


Open the class and create a new Function called BlockMovement.

Open your character class, go to Class Settings and Add the Interface.

Implement your Interface event. My Blueprint → Interfaces
Right click the Event and select Implement Event

You should now have an Event Block Movement added to your Event graph.

Move the event so it’s inline with the movement input.
Use a FlipFlop (temp solution to prototype) and setup your Boolean.

Now create a Macro… Is Movement Blocked

Next we add the macro to the movement logic.


Blocking Actor

Collision Settings
We only ever want to Overlap Pawn which is the obj type used for the characters capsule component.


We can adjust this to use two Interface Events.. e.g. Disable Movement, Enable Movement

BPI_Pawn (interface class)

Character Class

BP_ForwardBlocking (Actor)


Usage

Add the actor to the map.
Move to general Location.
In the Details panel select the Collision component.
Using the Scale tool adjust as needed.

For finer control of scaling you can use the Transform → Scale, OR adjust the Shape → Box Extent.

1 Like

@BRGEzedeRocco @Rev0verDrive Thank you so much for your detailed responses. This will not only help me but the others out there that may also want to implement this. Thank you, thank you, thank you! :grinning_face:

Disabling “keys” gets trickier if you allow clients to do custom key binds and double mappings.

Also using Player index nodes won’t work in a multiplayer setting.