I’m building interactions in my third person game right now. Think doors, levers, chests, etc. The method I am using is placing a sphere collision around any object that the player may interact with. If I walk into it, then I save the object to be interacted with. I’m just wondering, is there a more optimal way to do this? It all works fine at the moment but would like to hear other ways.
I personally believe the best way to do this is with Blueprint [interfaces][1].
This allows a level of abstraction where the interactor does not have to do anything but ask the other actor “Can I use you?”
In this rough example I create an Interface that has a simple interact event linked to it.
Then I create an input event called Interact (this is confusing naming but it was a quick dirty example). I link that to a trace that fires in front of the player when called and any actor that is hit I send the interact message to.
Then any actor that I want to perform some action when it receives the interface message, I add the interface to it in the Class Settings and link up the Even to whatever logic I want it to perform.
In this case it toggles a light on and off, but it can literally do anything and the “calling” actor doesn’t care what it’s logic is, and it has no hard references to anything, which can be an issue with blueprint communication.
[This][5] is probably a pretty good watch to get more of an understanding of using Blueprint Interfaces.