How do I make a button to press on an object to interact with it?

I’m quite new to UE4 and am doing a project to make a 2D game, which mine will play like a top down game. I have gotten the player character’s walking directions working but I am trying to make it so when the E key is pressed on an object next to them, it will interact with it.

The idea for the object is to have it get destroyed when the player interacts with it and have a message pop up stating so. This will let me know if the player can interact with the object. I’m wanting to have it so in order for the player to interact with the object they must be standing next to it. Below is what I had tried to do. The top one is what I wanted to try and get it to do but I couldn’t make it work. The bottom (when connected) would show the message when the player walked into the object.

Look there are many ways around this, I’ll show you one and you try to find the most suitable for your game. If you can already get the object when you go into it’s boundaries (I’m guessing with a sphere or box component checking on the trace channels), just set up the input for the E key: In the Editor go into Edit->Project Settings->Input(under the Engine tab) and add an “Action Mapping”, call it whatever you want and link the E key to it (press on the + symbol). Now you have a mapping for the E key but you have to bind it to the action you require in your game, for that go into the Player Controller (some people place the binding on their Pawn, whatever your taste is) and (I’m guessing you are using Blueprints) right click on the event tab and find the mapping by the name you gave it. Now create a variable in the Pawn/Character to store a reference to the object once you enter it’s boundaries like you said you were doing and from there go to the player controller, grab the “On Press” event, get a reference to the controlled pawn, cast it to the pawn class you have and access the object reference to destroy it or whatever you want to do with it.

If you have more questions like this one I recommend you to ask for help in http://unrealslackers.org/

Hope this helps!

Just read your answer and trying to implement into my game, but found a couple problems/things I don’t fully understand. Also forgot to note that I am using the 2DSideScroller template for the game, as this was what was shown to us for the project, and have edited the player character in that map as my player now. Questions are below:

  1. When you mean boundaries do you mean to set up a trigger on it or the collision with the block?
  2. Player controller - I think I understand what this is but in case i’m getting it wrong would this be the blueprint of the player or a different object on them?
  3. By event tab do you mean right clicking in the event graph or is there a tab I’m not seeing? Only tab I see that isn’t the graph is Event Dispatchers which has nothing in it.
  4. Couldn’t find the On Press event you mentioned. Did you use that as an example name of a variable I should’ve made? Made and called the new variable “Interact” and tried dragging off the node, right-clicking in the graph and typed in on press and had nothing come up.

I’m also using in version 4.15 which may not contain some things you may have mentioned (not sure if this is a problem but noting just in case). Will probably also check out that Discord server in the future if I have any issues later on :slight_smile: