Best way to make a "modular" interactable system?

Hi,

I was wondering if you have any suggestions on what the best way to go about making a system that allows for any BP to be “interactable”, meaning, the player can interact with it. And of course, different things happening depending on what object it is.

Currently I have an interface I just call iInteractable. Then the player checks if there’s any object close to him with that interface (and which is closest). If so, show the “Press X to use”-HUD and when pressing X, call the “Interact”-function on that object.

It works surprisingly well and I can use it on pick-ups and buttons alike. The problem I’ve run into is that I’m not sure how to deal with something needing to “turn off” afterwards. Like a button. Once pressed, it should no longer be interactable. I basically need the objects to have an active state.

Is there any way I can with an interface or something similar force a Blueprint to have a variable, like bActive?

I don’t mind changing my setup completely if you have some amazing suggestions. The reason I’m not doing it with inheritance is that I want to be able to make anything Interactable, so I can’t find a good structure hierarchically.

Thanks,

You can set the output in the interface to return a bool. In the interface class, select your function and on the right you should see the option for inputs and outputs. Hopefully this helps. :slight_smile:

Yeah, I tried that. The problem I had was that doesn’t create a variable for the BP. So I’d have to (if I’m thinking straight) set that up manually in all the BP’s .
Thanks!

You could also create a base class for all your interactable stuff and create children off of that. Put your variable in that base class and all of your interactable stuff will inherit it and any functions you put in there!

Yeah, I was thinking about something like that, but I’d prefer if the system was more modular than that. The problem is that I want (if possible) to be able to make “anything” interactable. If it was only for pickups, or pickups and buttons it’d be easily doable with parents. But if I all of a sudden decide that I’d like for something else to be interactable - I wouldn’t be able to just “attach” that functionality.

Thanks,