Access member function of another C++ component

The type of interaction possible should be tied to the object you’re interacting with. The interacting character does not need to do anything other than sending the interaction request. This way you only need 1 interaction component, and you can reuse this component across all actors that are interactable.

Any object that is interactable should be marked as such, ideally by creating a component or interface for interactables that can be added to any actor that you wish to interact with. I personally use a component, since I can tie widgets to it.
This component can hold multiple types of interactions. You could have a series of booleans exposed to blueprint called “canGrab” or “canBasicInteract” and so on. Add a UMG widget to this interactable component to display information to the player if needed.
The benefit here is that opening a chest and pressing a button are basically the same interaction, but you can for individual actors have an interaction text that says “Open Door” and “Press Button”. You can also have different interactions happen depening on the interactable actor. Again, the interacting character does not need to care about anything other than sending the request, so it’s important that we keep it that way.

When interacting with an interactable, you can get the actor in question from your HitResult. I would suggest using a LineTrace, so you interact with whatever you’re looking at. From there you can call whatever functionality needs to be done. Call the actors through the interaction component.

If you do it like this, any actor that has an interactable component, can be interacted with, it will show a widget to the player and it will be easy to customize.

Hope this makes some sense.

EDIT:
To put this into some perspective, imagine you have a game with multiple weapons.
When the player presses left click, they expect their gun to shoot, their sword to swing and their bow to draw. The character does not care what weapon is equipped, it just wants to tell the weapon to attack. Same sorta deal here, just with interaction.

1 Like