Trigger an even based on a set number of key presses

In the below BP I have a simple triggervolume to trigger a matinee when my character overlaps with a box. How would I go about doing the same thing but the character would have to hit 3 boxes in the right order?


I’m guessing that I need to make a single blueprint with the 3 cubes in it and have a bool set to true but thats as much as I can figure out so far.


I’d probably go for something like this:

-Create a new actor and call it “BP_TriggerObject” or something like that (I’ll use that name in the example).
-Add a static mesh component and a collision sphere (or box).
-Create a static mesh variable and set it to public. Now you can create a function and the static mesh in the construction script so you can use any mesh you want while keeping the “sequence trigger” behaviour.


-Create a new int variable, name it something like “PositionInTriggerSequence” and set it to be public as well.
-In your Character BP make another int variable called “TriggerSequence”, or just “Sequence”, or whataver you feel will fit best ;). I used the character BP in the example, but you might want to use your GameState BP for this instead, depending on your needs/workflow.
-In the Sphere/Box Collision -called Trigger in my example- add an OnComponentBeginOverlap event and use the script below:


Now when you place a BP_TriggerObject in your level you’ll be able to change the mesh and its order in the trigger sequence by editing the public variables we created a while ago :slight_smile:


As you can see in the example, I placed a cube, a sphere and a cone in the level using the same BP. I set the PositionInTriggerSequence to 1 in the cube, 2 in the sphere and 3 in the cone, and that’s the order the player will have to “touch” them to play the matinee thingy.

If you don’t know what the script does (no mean to insult you or anything, I’m just trying to explain myself as best as possible), it basically uses the TriggerSequence variable (the one we created in our CharacterBP) to store the latest actor the player “touched”. Whenever the player overlaps the sphere/box collision, it checks whether or not the stored value is equal to the position in the sequence we set when we edited the PositionInTriggerSequence variable. If they’re the same value it updates the TriggerSequence by adding one, so now the stored value will be 2, what means that the TriggerSequence won’t update again until the player overlaps a BP in which the value of the position in sequence is 2 (in our case that’s the sphere). In the example if the player touches the wrong object I reset the stored variable so he/she needs to start over the sequence. But if you don’t want that to happen just remove the Set Trigger Position from the false output in the first branch.
Finally, it checks if the TriggerSequence is equal to the number of objects in the sequence -that’s 3 in our example- and if so it plays the matinee sequence and reset the trigger sequence variable (this is optional). Note that we’re triggering the matinee sequence directly from the BP instead of using the level blueprint. Also I’m assuming you only have one matinee actor in your level, hence the 0 in the Get node. If you have more than one you’d need to specify which one you want to play.

This is actually the “simple way” I’d use. If you for example want to, say, destroy the objects after playing the matinee, or make them glow or blow them up or whatever, you can use the same approach but instead of using an integer as the TriggerSequence variable you could use an array of the TriggerObject blueprint and check its length. If it’s equal to the position in the sequence add that object to the array. After playing the matinee simply use a for each loop to get the actors stored in the array, and now you can do whatever you want with them.

I’m no expert actually, so there may be a better way to do it (and if so I’d be glad to learn it too!). However, I think this is a pretty versatile system. It can be easily extended and modified depending on your needs.

Hope this helped!

Regards :slight_smile: