Create a "use" function for multiple objects/events

Hi everyone, so today I was trying to create some blueprints and functions for a game I am going to make. One of the things I want to add in is a “use” function where you can press E to activate certain events once inside a certain range. For example; turning on and off a light switch, opening doors, and picking up objects. I am really new to UE4 and have looked around for tutorials on how to do something like this but I couldn’t find anything. Right now I’m just trying to get this to work with a light switch but am not sure how to set it up. If I could get some help, a link to follow, or some guidance that would be great!

Thanks in advance!

if its just for one item you could use a combination of a collision box with a begin and end overlap events combined with a input event such as pressing the E key. Essentially with this method you check is the player is within range to use the item, then have a separate event to actually use the item.

If its for more than one item i would look into using blueprint interfaces.

Good Starting Point Tutorial


Before you start implementing this, you should think how exactly you want it to behave.

Do you want the item to be usable whenever the player is nearby, even if they are not looking at it?
You can do that with a simple collision/overlap sphere.

Do you want them to have to be facing the item?
You can do that with a collision/overlap sphere and by checking the player’s facing direction angles.

If there are multiple items nearby, how will you choose which one to use?

Do you want to only use items near the centre of the screen (if the game is first-person)?
To do that, you’ll need to raycast out from the player’s view to find the item.

… both Thompson and Nameless are right…

as you say, Sea, you can use a Blueprint Interface to send the same “use” message to many different types of actors… say a door, a health pack, etc. When the referenced actor gets the “use” message, they can interpret this in their own way (a door opens, a health pack adds health, etc.)