I’ve implemented a mechanic in my project where something happens if you hold down a key and click while the key is down using a boolean so when the key is down it sets to true, when the key is up it sets to false, I’ve noticed that after I clicked, the game thinks the key is lifted so it sets the boolean to false, Does anyone know why, and how to solve this? To summarize, clicking while holding the key triggers the released event. Thx, -P.S. I’m using an umg.
Sorry, but saying “I’m using an umg” is not enough. There are too many variables to consider. Show us how you doing all this.
Are you working on laptop? I have similar issues with laptop where both mousedown and mouseup fires when i release mouse button. This is because laptops keyboard and mouse has lots of ghosting issues. My laptop wont even take mouse axis input when i have wsad pressed. If you are working on laptop you can solve this by connecting external keyboard and mouse and use them instead of inbuild keyboard and trackpad.
I’m using an umg.
This tells little, but let’s say that’s all the info we have. Widget handling Left Shift:
And the mouse click:
Setting Keyboard focus may be optional, here. Depends on how other things are set up.
Regarding my lengthy comment above, I’ll just add that the Handled / Unhandled here is what controls how the Widget and the Player Controller respond to the input.
Essentially, if you pass Handled, you’re indicating you’re done with input processing and nothing else should receive it. If you pass Unhandled, the input will check for other widgets underneath and if it finds nothing that could Handle it, the input will be passed on to the Player Controller.
The above assumes we’re using Input Mode Game and UI.
I am using a laptop, and I was using the character blueprint to detect the key event, I have an input action set up and when the key is pressed it will set a boolean to true, telling that the key is down, and when the key is released the boolean is set to false, My laptop doesn’t ghost when holding down a key and clicking at the same time, Later I’m going to try using the widget to handle the key event like everynone said.
Later I’m going to try using the
widget to handle the key event like
everynone said.
Just to give you some heads up, the Player Controller generally does not know what’s happening with the input when the player is fiddling with the widgets, and vice versa. So you either want to handle all input for the action in the PC or in the Widget.
Detecting shift in the player controller and left click in the widget will not work well out of the box. It can be hacked to work but I’d generally advise against muddying the water.
In most cases the player will be either focused on the inventory management or game world interaction. If you must reload rockets from the backpack and reorganise the hotbar while simultaneously bunny hopping off a cliff, it can be done but it’s somewhat awkward.
Thx for your answer to my question, I’ve done something similar to what you did but used a save game to detect if the key was pressed before the widget was created and it would respond to it. Before I was using the character BP so it didn’t work as well as using the widget and a save game.