Download

Interact with actors trough events?

Hello everyone, i was wondering what would be the best way to have an “interaction button” for a game with rpg elements. I was hoping there would be an easy way to add an event that any actor could receive, like on hit, on overlap, any damage (not the custom events that are only specific to one class). So that i could use it for interactions. Something similar to the way damage is done would be perfect, so i could use a ray cast to get the actor i clicked on, and have an “on interaction” event in every actor that activates when that happens.
The way i thought of doing this was with a volume that appears in front of the camera (or at the end of a raycast to make it more precise) when i hit the “interact” button. And then in any actors i want to have interactions with, i must have a “on component begin overlap” then a cast to check if its the invisible volume and then do whatever its supposed to do when you interact with it. But i feel there should be an easier way to have an interaction buttom and actors to know when you want to interact or speak with them.

Take a look at “interfaces”. The interface specifies a number of functions. You can implement it (the functions) on any actor. You then just raytrace and for the first actor hit, call one of the interface functions (for example “interact”). If the target actor don’t have the interface implemented, the call just fails silently.