You can use Blueprint Interface to accomplish this. You create a blueprint interface which is essentially just an event, that can take an input or an output.
I’ll show you my example, I have a system whereby I determine the closest interactable object to me by using a dot product of my mouse cursor position (although the cursor is hidden ingame and there’s no crosshair as the mouse controls the camera). I then use BPI to communicate with whatever the closest object is.
From my character blueprint (input action is simply a keybinding, in this case “E”) where it sends to the specified target via a message (which then triggers an event in the relevant actor):
This is what the BPI looks like:
And here are three examples of how this applies to an actor. One is an item that is dropped on the ground which I am picking up, another is a merchant or NPC I am talking to and the third is a bomb that I am defusing:
To utilize these you need to open the class settings in the relevant actor blueprint and make sure you implement the interface:
Everything is done entirely without casting as I cannot know what exactly I am interacting with. Is it an item? Is it an NPC? Is it a lever or a button? A door? BPI functions exactly like casting except you don’t actually cast it.
You do need to define an actor as a target though, but that is very simple. If you don’t want to go for more advanced functionality like mouse position, you only want to use your characters location for example, you would go ahead and do a multisphere trace for objects and simply pull out the closest one. The radius would be your “interactable area”. Or you could go a bit more archaic and simply add a sphere collision to your character, which stores the item in an array and run a foreachloop to check which one is the closest one.
And as you can see you can have multiple events or functions trigged by the same BPI. Having different ones can be helpful to ease strain as well as organize yourself. For example I have a separate interface for dealing damage. This interface does not need to be implemented by things that cannot receive damage. Like chests, friendly NPCs or triggers.
Hope this helps!