I have an input action for Use, which is bound to E in the Input Context.
If E is held down when the context is added to the input subsystem, it starts triggering its Started and Completed functions one after another indefinitely until it’s released or another key is pressed (surprisingly, any key, even if it’s not used for any binding).
The Triggered is fired too, and this I would understand (even though bIgnoreAllPressedKeysUntilRelease is set to true, but okay), but I can’t figure out why Started and Completed keep firing.
Forgot to mention: when I’m adding a context with a higher priority, everything seems fine.
In this case I add one context and remove the other, all with priority 0.
Basically, I switch between game inputs and UI inputs, and I do it this way because there are a lot more game inputs than UI inputs, and to simply use a context with a higher priority would mean I’d have to override all the bindings of the game context, which seems unnecessary.
The order of adding a new context and removing the old one doesn’t make a difference.
The way it works in your system is what I would expect.
In my case with one additional context it works fine, but wrong with the other. I’ll have to experiment some more and determine why that one context triggers such abhorrent behaviour and I’ll come back when I’ve found something.
Turns out this happens not because of adding a context, but actually because of some of my widgets.
So my test setup is:
A brand new Context with a brand new InputAction, not used anywhere else;
A delay that creates a widget and adds it to viewport (the delay is needed because if I simply create a widget with a keypress, this keypress may affect the issue);
I press the key that starts the delay, and then press and hold the key assigned to the new InputAction in the new Context;
My widget appears, but it’s still okay, nothing weird happens;
Then after another delay, I set focus to the newly created widget. And only after focus, the Started and Completed of the new InputAction start triggering like crazy.
I tried doing the same with a fresh test widget, and couldn’t reproduce it. I tried stripping down the widget that does cause the issue to its bare minumum, deleted all functions and changed its parent class to UserWidget, but the issue still persists.
Okay, I dug deeper into the engine code and seem to have found the issue.
The thing is, if you have a focusable widget and it’s being focused, something else gets unfocused, which eventually results in calling FlushPressedKeys() in PlayerController.cpp and PlayerInput.cpp, and for some reason it starts triggering this weird behavior as described in the first message.
You can easily reproduce the issue as follows:
Create an empty widget class derived from UserWidget and set its IsFocusable flag to true;
Create a mapping context and an input action, add the action to the context;