I am trying to create functionality to allow the player to re-map input keys at runtime. I am doing this with a simple UMG widget and the current state allows players to remap keys without any issues (at least that I am aware of)
I would like this functionality to support chorded and non-chorded actions. Basically, the player clicks on the action they would like to remap, they press either a single key or a series of keys and then the logic would remap that input and dynamically create a chorded action trigger and assign it to the action, or not if only one key was pressed. I am having trouble finding any information on how to dynamically create a chorded action trigger and assign it to a player mappable input. Can someone please point me in the right direction? The current logic uses blueprints, but if C++ is required then I can convert the logic over to C++.
Thank you for your reply 3dRaven. Unfortunately (unless I am missing it) the video you posted only covers basic remapping of the keys and does not cover adding triggers at all and specifically the one I am interested in is the chorded action trigger.
If anyone knows how to dynamically create chorded action triggers and associate them with actions in the enhanced input system I would very much like you to share that knowledge
Thank you for the reply 3dRaven and apologies for the lateness of mine
I have been reviewing the code you provided and I do have a follow up question if you don’t mind:
One of the arguments is “ChordedAction” which is used to set the ChordAction. Do you have an example of how this argument might be prepared in the calling function?
Just as an FYI there are a couple of small typos in the solution, namely that JumpAction and DefaultMappingContext are not defined but that did not alter the spirit of the solution. I just mention this in case someone else is reading this and was confused. What I have done is to replace JumpAction with Action and I added an additional parameter for DefaultMappingContext.
DefaultMappingContext is created automatically if you create a template character project with c++.
The ChordedAction element as you can see from the definition is just a second UInputAction passed in the function.
A new UInputTriggerChordAction (a form of wrapper) is created on the fly and the second input action is passed in as it’s parameter along with the threshold of activation.
The new InputTriggerChordAction is then passed to the first actions triggers.
You are fast, I attempted to modify my response but you had already responded
Thank you for the additional information about DefaultMappingContext. I have been working in a blueprint function library which is a static context which explains why I would not have access to that.
After looking through the code again I realized that I may not have understood the ->ChordAction function. Does this add a single “key” to the chorded action trigger. So if I wanted the input to be J + T + F + K would I create the input for J using the logic you provided and then call ->ChordAction on the J input once for T and then for F and again for K?
If you want to expand it to multiple keys then modify the code to take in a TArray<UInputAction*> ChordedAction and a TArray of floats (or go all out and make a struct for both)
I had made the changes in the project I had been working on, but unfortunately the code wasn’t having any apparent effect. I confirmed that the C++ function was calling the Triggers.Add for each InputAction that I passed in, but when I attempted to use the input it did not fire. I also checked the context’s mapping values from blueprint and there doesn’t seem to be any action added. I assumed the issue was related to the fact that I am working in a function library and perhaps the World reference I am getting is a bit off or something.
To simplify things (as there is a lot of code in my current project) I have created a fresh project using the 3rd person template (5.3.2). If I understand your earlier comment, you were using a class derived from the Character class, so I have created a class from Character as well. When I attempt to compile the code, I am still getting an undeclared identifier error for DefaultMappingContext. I suspect that I am failing to understand something fundamental so I thought I should ask
On a related note, I am also having trouble creating a UInputAction. Can these be created dynamically or must they exist as an asset at runtime?
You can set the input actions as either soft or hard references to a UInputAction pointer.
Just make sure you expose it with a UPROPERTY macro.
I’ll try to make a quick project and see it I can do multiple triggers
edit: Started reworking the project and chorded seems to only work with 1 trigger (3 are seen but just works with 1).
Got combo working but requires the buttons to be pressed in the order you pass them.
Chorded will only register the last trigger you add
So combination of base button + last chorded trigger.
Thanks for your efforts. Sadly, I have been unable to get even a simple remapping to work (triggers or not) so I fear that I am missing something. I will continue to work away at it, but if you wouldn’t mind sharing your code I would be very interested in seeing it.