Half-Life'esque trigger system

Half-Life1 was simple but robust in it’s trigger system. You get an interactive object called “entity”, that object have a simple name. any other entity on the level could locate that name and trigger it (if their functional allowed that), making the item do a thing. Or items, if several had same name.

The thing is, in UE it seems that the only way to interact with other blueprints and instances is Cast To node. Which wouldn’t be as bad… if it wouldn’t be so ■■■■■■■ PICKY with how it must be set up. So if I want one blueprint instance of a button to open a door, and another instance of the button blueprint to switch on a light… I can’t. I must make a copy of that blueptint and change it’s Cast To setup so it would cast to lights and not doors. Yeah so far nothing too bothersome, but if I’m working on large map that should have tons of various objects that need to trigger each other? I’ll end up with piles and piles of instances and copies, that will be a nightmare to navigate and manage!

I really hope I just inexperienced and thus oblivious to a simple solution… So how could I setup the described functionality? Blueprint fires a function that looks up a name set up in “target” variable of that blueprint, searches the map for any and all blueprints that have matching “name” variable, and makes them do the thing, say, fire an “OnUsed” custom event.

You can use Blueprint Interface to accomplish this. You create a blueprint interface which is essentially just an event, that can take an input or an output.

I’ll show you my example, I have a system whereby I determine the closest interactable object to me by using a dot product of my mouse cursor position (although the cursor is hidden ingame and there’s no crosshair as the mouse controls the camera). I then use BPI to communicate with whatever the closest object is.

From my character blueprint (input action is simply a keybinding, in this case “E”) where it sends to the specified target via a message (which then triggers an event in the relevant actor):

This is what the BPI looks like:

And here are three examples of how this applies to an actor. One is an item that is dropped on the ground which I am picking up, another is a merchant or NPC I am talking to and the third is a bomb that I am defusing:

To utilize these you need to open the class settings in the relevant actor blueprint and make sure you implement the interface:

Everything is done entirely without casting as I cannot know what exactly I am interacting with. Is it an item? Is it an NPC? Is it a lever or a button? A door? BPI functions exactly like casting except you don’t actually cast it.

You do need to define an actor as a target though, but that is very simple. If you don’t want to go for more advanced functionality like mouse position, you only want to use your characters location for example, you would go ahead and do a multisphere trace for objects and simply pull out the closest one. The radius would be your “interactable area”. Or you could go a bit more archaic and simply add a sphere collision to your character, which stores the item in an array and run a foreachloop to check which one is the closest one.

And as you can see you can have multiple events or functions trigged by the same BPI. Having different ones can be helpful to ease strain as well as organize yourself. For example I have a separate interface for dealing damage. This interface does not need to be implemented by things that cannot receive damage. Like chests, friendly NPCs or triggers.

Hope this helps!

Thanks! This sounds like it is exactly what I needed.

No problem, just ask if you need help. Main thing is finding a way to connect a target to your message so it gets sent to the right place. But once you get one to work it should be easy to replicate.

Actually thinking about it, with the right checks you could potentially do the same with a function library… oh well.

You’ve gone to class settings and implemented the interface?

If the target is correct it will trigger.

So, I set up this system as a test, on entering correct number in the keypad it should trigger the BPI which sends Trigger Action to object in the keypad’s Target variable, which I define per instance of the keypad. IN this instance, a box. Once box was triggered it kills itself. The setup:

Keypad is working, It prints out correct messages. But the BMI doesn’t seem to trigger.

I was basically a moron. I picked the object from a scene and then I turned it into a blueprint to add the killing action and forgot to re-pick it again. Once I’ve done that, everything begun functioning.
Now I’m looking at the save game functionality and being horrified by it. Epic documentation saying that I need to manually define every single variable of every single object that I want to be saved? there is no “save EVERYTHING” option?

Save games can be a little tricky yes. There are ways to simplify it, using structs and whatnot that can store a large amount of information is somewhat popular. And if you’re using master blueprints it’s a fairly simple thing to implement.

Suggest searching for tutorials and looking at the documentation.