UE4 Using Widgets as an input source?

I am building an elevator and as of now it takes keyboard inputs to determine which floor it goes to (click “2” and it goes to the second floor, etc.). However, I want to change it so that once the player enters the elevator, a widget pops up on which are numbered buttons and the player would be able to just click on the buttons in order to control the elevator.

Could anyone tell me how I can do this? (I am a bit new to the program so I would definitely appreciate a detailed response thank you!)

Use a button widget and call the same function that you call pressing the keyboard number in the “OnClick” event.

You might need to pass the elevator reference to the widget, create a variable of type elevator and set it when you create the widget

2 Likes

Did you got it after last advice?

How do I make the reference to the elevator? what type of variable would it need to be and how do I connect it to the widget?

My recommendation is to create a variable called ElevatorReference in the widget

It could be of type actor or if you want to be more precise you can use your elevator class.

When you create the widget in the elevator class (create widget from class) save the widget as variable and then drag from its output and set ElevatorReference to self



So right now these are what I have for the actual elevator. I created the button widget and made the public variable called ElevatorReference.

Should I add an EventBeginOverlap → CreateWidgetfromClass in the Elevator actor or the widget blueprint?


Also here is my attempt at the ElevatorReference stuff.

I’m having a bit of trouble understanding because I’m quite new to the program. I uploaded screenshots of what I have so far if you could help me out

In the Elevator BP:

  • During BeginPlay you create the widget and save it as variable, then set it’s parameter “ElevatorReference” to self

  • During BeginOverlap you add the widget to viewport

  • During EndOverlap you remove it from parent

  • Use a function with a parameter so you can easily call it from an external BP
    (I don’t know what your “Floor button” float parameter is, maybe you meant bottom?)

In the ElevatorWidget BP:

  • Assign the button onclick event, checking if the elevator reference is valid (right click on the regular get and click “convert to validated get”)

Let me know if it works, if it does pleas mark my answer as solution :blush:

1 Like

It works! Thank you so much!

1 Like