Unreal Engine 4 Tutorial – Open Close Door with Triggers and Matinee
A few weeks ago I created an Unreal Engine 4 video tutorial showing how to create a door you can open and close with the use of a couple of triggers and the animation tool matinee. It seems like people enjoy it, and so here it is:
And for those of you who’d like to have the steps written down, here we go:
First off, I want to set up the static meshes that I’ll use as the door knobs and the door. In this example, I’m not intending to do anything flashy, so it’s enough to simply utilize some of the already included meshes, add a material or two, and a static light just to make it look cozy. Like this:
I add another door knob-thingy on the other side as well, which closes the door. This one will get a red light, like this:
Our meshes are put up, so it’s time to add the triggers that will open and close the door. In Modes (1) menu up and to the left, click Basic (2) and locate a Box Trigger (3). Simply drag the Box Trigger into the game scene (4) and place it where you want it (most likely directly over the door knob, right), like this:
Make sure both door knobs have their own Box Trigger.
Your static mesh door will most likely be Static by default, which is no good if you want to animate it. Therefore, with the door mesh selscted, in the Details menu on the right side, under Transform, make sure the Mobility setting is set to Movable.
Now, time to create the open door animation. With the door mesh selected, open the Matinee tab in the top menu, then down in the Track section right click and choose Add New Empty Group. Name it whatever you see fit. With the new group selected, right click once more and (again, be absolutely sure your door mesh is selected) choose Actors -> Add Selected Actors.
This being done, right click yet again, and choose Add New Movement Track, which will create the track where you’ll actually animate the door.
By dragging the green triangles you can adjust the length of the animation sequence. You place animation keys by pushing Enter, and the keys will be placed on the timeline at the position of the black timeline bar. Since we’re now creating a simple door, you probably want it’s starting position to be shut closed, which it should already be, and so just click Enter to place a key at the beginning of the timeline.
Next, move the timeline bar to the end of the timeline, and then move the door mesh to it’s open position. Click Enter again to place a key for this position.
You can now drag the timeline bar back and forth in order to see the door’s animation play out, and make sure you’re happy with it. It should look something like this:
(If it doesn’t look like this, or you can’t get it to work properly – watch the video.)
Remember to SAVE YOUR FRIKKIN’ PROJECT 😉
Time for some Blueprints-magic:
Open Level Blueprint by clicking the Blueprints tab right next to Matinee in the top menu.
Select the Trigger Boxes in your scene (one at a time), and with each one selected, right click and either search or manually locate OnActorBeginOverlap. Like this:
This makes sure the trigger is activated as soon as the Player overlaps the trigger’s collision box boundary, which in turn will play the animation and open the door.
Thus, next step is to add a reference to the MatineeActor in the scene. This represents the door animation. Find and select this actor, either the symbol in the scene, or in the Scene Outliner in the upper right corner.
With it selected, go back to Blueprints, right click and write Play in the search box. Choose Cinematic -> Play
This will place a Play “box” in Blueprints, and if you’ve done it correctly, the MatineeActor reference should already be magically attached to it.
All in all, you want an OnActorBeginOverlap for each of your triggers, plus a Play for each of them (both of the Play‘s should be connected to the same MatineeActor, since this animation will play both the open and close animation).
To be able to close the door, however, we’ll need to add a little something extra to the second trigger, this because we want to reverse the animation when closing the door. It’s the same animation, but reversed. And so, right click in Blueprints, and type reverse in the search box. Choose Cinematic -> Reverse
This box you’ll attach to both the second trigger’s Play and the MatineeActor.
When all of these boxes are connected correctly, the masterpiece will look like this:
Enter your game and witness the beauty of an in-game door you can open and close. And, again, if something doesn’t work, watch the video.
UPDATE: If you want to open the door by pushing a button instead of having the doors automatically opening, then watch this follow-up tutorial: