Download

How do I create a c++ based system for rebinding keys at runtime? (UE 4.24)

I am currently working on creating a c++ based system for rebinding my keys ar runtime.
I am able to do it using Blueprints, but my project lead has mandated that it is done using c++ in order to make it easy to expand on and in order to avoid the kind of nightmarish blueprints we would end up with.
The general issue I have is that the majority of c++ resources I have been able to find appear to be either outdated, extremely difficult to interpret or lacking crucial information.
I should also mention that I am still learning c++ and have not quite been able to wrap my head around it yet.

With this established, here are the problems I am having.

In my c++ file, I want to be able to access the Key Input Selectors in my UI widget and recieve the input from them. The problem is that I cant seem to define them in the h file. I have tried a few variations, but UE always throws an error when I attempt to compile it and I have thus far been unable to find a example to replicate.


UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
UInputKeySelector* pInputKeySelector_FireWeapon;

Here is one of of the ways I tried to implement it based on how I have done similair things previously (the IKS in the widget is called pInputKeySelector_FireWeapon).

Secondly, I have a hard time coming to terms with the syntax of the commands I would need to use in order to actually change the binding. Based on advice I have recieved elsewhere I attempted to implement the command AddActionMapping, but I have trouble understanding how I would actually implement it, meaning that I do not understand which arguments I need to pass into it and how to formulate them, aswell as how to pass the input from the IKS into it.

What I really need are concreate examples of up to date code as well as help understanding said code.

Any help would be appreciated, Thank You.

I would suggest that you look at the different node that are avaible on this topic and learn the C++ from their source code.
You can use the Widget dedicated for Key capture and send the inputchord struc to your C++ and make the command binding in it.

I have made several attempts to find the source codes for the relevant nodes using “Goto Definition”, but have not been succeseful thus far, the function just does not seem to do anything.
I am aware that UE4 has the Input Key Selector (which I refered to as the IKS) for getting key inputs, but I have not had any success in understanding how to use it with a c++ script, I cant even seem to define it in the h file.

I hope I do not come across as snarky or ungrateful, I just feel like I have tried every possible way to find examples of how all of this would look like once implemented into a script.
I have a very limited experience working with c++ and I just cant wrap my head around Epics official documentation.