Download

Enable Key Press Within Radius?

I’m working on a universal interaction system for my 3rd person project, and I’m having trouble putting together something that only allows interaction via a key press when within a certain radius. I’m also using a player controller, and passing input to a player character, so there’s an extra step than just working directly with a character.

I know about overlap events, but I can’t seem to get something working that passes the overlap from the character to the controller, and allows for a key press when overlapping a valid interactable.

Anyone have any advice or suggestions, or even working examples?

You can do this a few different ways, here’s a simple way.

Have your player controller process the key press no matter what and call an event/function (let’s call it “OnInteract”) on your character to handle that key press.

On your character BP, when your sphere collider overlaps something, first check to see if the other overlapping actor is of the class you want to interact with via cast, and if so, set a boolean on the character that is enabled on correct overlap (let’s call it “InteractibleOverlap”). When overlap ends, the boolean should be set to false.

So when “OnInteract” is called by the Player Controller, your character should first check if “InteractibleOverlap” is true. If so, continue with the rest of the code. If not, do nothing.