Creating one USE key for multiple events

If you want to have a lot of different interactive objects triggered by the same button press, it may be best to create a Blueprint Interface function for it. The setup in the tutorial using level script and toggling player input is really only useful for a one-off situation, and not a good way to structure things if you want a lot of interactive objects for a game. Ideally, you’d want to keep all your input events inside the player pawn Blueprint and use one function for all interactions of a particular type.

So, once you’ve created an Interface function, you can go into your player pawn and call it like this:

This is going to try to call the Interface function on all actors currently overlapping your pawn when you press E, but only Blueprints containing the corresponding Interface event will actually do anything.

Next, in the Blueprints for your interactive objects (such as a light switch or button), you need to click the “Blueprint props” button at the top, then add your Interface asset in the Interfaces section. This will allow you to add events for the interface functions, like this:

So, if this Blueprint is overlapping your player when you press E, that event will fire and you can hook up whatever toggles or timeline animations you need to it to do. The final thing you’ll need is to include box or capsule components in your interactive objects to use as overlap triggers, so when your player is overlapping the component they can interact. There are a lot of examples of that set-up in the Blueprint_Communication Content Example I made, specifically in example 3.2.

With this kind of structure you don’t really need to use the level script at all, which is handy if you want to have a lot of interactive objects and don’t want to have to set up triggers and events for every instance of them.

1 Like