Map a UI button to an input?

Is it possible to map a UI widget button to a user input? For example: whenever the UI button is pressed, it is the same as pressing the ‘3’ key on the keyboard, and will activate my standard input action mappings.

My UI button is in a UI Widget.
My “Pressed” input is in the ThirdPersonCharacter blueprint.

If possible, can someone please show screen grabs of the blueprint solution?

Thank you,

I don’t know if you can call an input action directly but you can get the same effect like this:-
In your character blueprint add a custom event node. Call it MyPress (or whatever you like).
Now, set this event to do whatever your key pressed input action was doing and, make your input action call MyPress.
Test now and your keypress should do exactly what it did before.
But, now we have the event MyPress that your widget can call.
Now, in your widget use the button onclick event. In the onclick event ‘get all actors of class’ and select your Thirdpersoncharacter. Drag out from the output of this node and add a get node - if you only have one character then get 0 will be fine. Now call event MyPress.
Test again - Now both your keypress and clicking the widget button will call the same event - MyPress.

Hello Podgyhodgy, did I do step 3 “My Press” correctly?
Step 7 “Get” connections could not be made. Do I need another type of Get(ref)?
I’ve attached a couple screen grabs to help communicate what I have done.

From what you have shown:-

  1. in the playercharacter eventgraph drag out of the J pressed and Call the MyPress event (just type mypress in the context sensitive node selector menu and you should be offered it.). With this in place you should be able to Press J and that will call MyPress that will execute your following nodes.
  2. In your ui widget drag from the ‘Out Actors’ to the top left of the Get node (the one that matches Out Actors and is greyed out). If this will not connect then delete the Get node and drag out from ‘Out Actors’ then right click and type Get - select the Get in the Array category. It will then know for sure what sort of array it is getting. I have had the Get fail on me when I have changed the Actor Class presumably because the Get is expecting a particular class and will refuse others. Delete and re-create is what I do.
  3. Leave the zero in the Get alone. Zero will get the first Actor your class.
  4. Now drag from the output of the get, right click and type MyPress. Select the node to call event MyPress.
    That should be it.
    I will check back to see if you have succeeded.
    A couple of extra points:-
  5. You could create an input action event in project settings and assign it to the J key instead of using J pressed if you like.
  6. The widget button does actually have pressed and released events too - which I forgot about.
  7. If you had more than one actor you would put a loop between the Get all actors of class and the following Get node.
    Good clicking.

Hello, Podgyhodgy, I tied out the Event Dispatcher to hook up the widget UI button to the ThirdPersonCharacter blueprint. The Dispatcher seems to work fine, what do you think?

There are three ways that I know to get one blueprint to communicate with another:-

  1. casting like I suggested.
  2. Event dispatchers (listeners or talkers)
  3. Interfaces

There may be more that I have not heard of. My attitude is that if a technique is giving you the results you want then it is a good technique. In a large complex game with many actors you might want to start worrying about which will give the best performance for your particular circumstances. There is always more than one way to skin a cat and some things that are not supposed to be possible become possible if you program in C++. For instance, plain flavour actors are not supposed to receive keyboard input but a while ago I wrote a bit of code that allowed an actor to do just that.
There is no end to it - there really isn’t. That is both the fun and the frustration of programming.

Thank you for helping me out, podgyhodgy. :slight_smile:

Hey Podgyhodgy, I appreciate the advice you gave me.
Have a great weekend. :slight_smile: