Door
We are going to create a door Parent that can be used to Open and Close any of the Child Events (remember the parent and child in Blender?)
Open your Content Drawer and in your Blueprints Folder, add a new folder called Doors
Open your new Doors Folder by double clicking it
then Right Click and add a New Blueprint Class
Select Actor
Name the new Blueprint BP_Door_Parent
Open it up by double clicking
Add a Static Mesh from the components tab on the top left and name it DoorFrame
Add a second static mesh and name it Door
Compile and Save
With your DoorFrame Component Selected, search for a door frame in the details panel under static mesh and select
Select your Door Component and search for a door in your details panel under static mesh
Move the door so that it fits in the doorway (You may turn off snapping if you want to be precision)
Compile and Save
Open the Event Graph for BP_Door_Parent
Right Click and add a custom event and name it OpenDoor
Right Click and add a custom event and name it CloseDoor
Add a Timeline and call it DoorAnimation
Connect the Open Door event to Play
Connect the Close Door event to Reverse
Double Click on your DoorAnimation Timeline to open it up
Change the length to half a second 0.5
Click on the +Track and add a float track
Name it Door_Alpha
add Two keyframes (Right Click)
Add the first on time 0 and value 0
Add the second on time 0.5 and 1
Select both Keyframes by shift click
Right Click and select User
Compile and Save
Return to the Viewport of your Door Animation and Select the door
Select the rotate Button
Click and Hold the Blue Area to rotate the door open
Rotate it and notice the degrees then rotate it back (we will set it at -110 Degrees
Go back to the event graph and add the door component to the graph
Pull out a link from the Door Component and add SetRelativeRotation (door)
Connect Update
Pull out a LERP from New Rotation to rotate
Connect the Door Animation Timeline to the LERP Alpha and Check the Shortest Path Box
Change the Z Value of your B LERP to -110 (The rotation of your door)
Create a Comment to Group
Compile and Save
Opening the Door
Child Blueprint and overlap
In the Blueprint for the Door Parent, select the Default Scene Root in the top left
The door is currently too small for the player to fit through so we need to increase the size
In the details panel under transform, change the Y Value (Green) to 1.5 and the Z valuer (Blue) to 1.3
Open up your content drawer on the bottom left
Select your doors folder in Bluerprints
Right Click on the BP_Door_Parent
Select Create Child Blueprint Class
Name the Child BP_Door_Overlap
Double click to open it up
The goal is to get the door to open when we get close to it
To do this, we need to add a collision (just like we did with the lights)
Click on the +Add under components and add Box Collision
We will make the box collision pretty big so that we can get it to work at a distance
In the details panel, change the shape to X= 400 Y = 250 and Z = 200
Then move the box collision so it is around the door
Find collision in your details panel
Make sure Generate Overlap Events is checked and Collision Preset is on OverlapAllDynamic
Find events on your details panel
We will create ab event by clicking the + On Component Begin Overlap
This will open up an Event Graph and add On Component Begin Overlap (Box) Node
Select the Box in your components and then Click the + in Detail > Events > On Component End Overlap
You should now have two events on your event graph
One for begin (open) and one for end (close) when the player gets to the collision
In the begin node, pull out a link fr om Other Actor and add search for == to get the = Node
Right click on your Event Graph and add Get Player Character Node
Connect the return value of the Get Player Character Node output to the Select Asset Input in the = Node
Add a branch
Connect the Output of the == Node to the Input Condition of the Branch
Connect the output Exec from the Begin Overlap to the input Exec of the Branch
What's happening here is that we are setting up the door to open when the character hits the collision box
From the Branch, pull out a connection from True and add Open Door Node
Copy and paste the Get Player Character, == and Branch Nodes then paste below
We are doing this so the door will not close if another Pawn (NPC) leaves the area. We want it to only trigger for the character.
Connect End Overlap Excec output to exec input of the new branch
Connect End Overlap other actor output (blue) to the unused input of the ==
From the branch connected to the End Overlap, pull out a new connection called Close Door
Select your work and create a comment called Overlap - Doors
Compile and save
Return to your FirstPerson Map Viewport
Open your content drawer
Drag your BPC_Door_Overlap in to your game
When you overlap (touch the collision box, your door should open
Pressure Plate
Creating an actor that will work as a pressure plate that will open a door
Open your content drawer and open doors folder then right click and create a new blueprint Class Actor
Name it BP_PressurePlate
Double Click to Open the Event Graph
Add a static mesh component in the top left corner
Name it PressurePlate
Select your PressurePlate Mesh and in the Details panel on the right side under static mesh, select cube
In the Details Panel under Transform > Scale, change the Z from 1.0 to 0.1
Compile
Add a Box Collision in your components (top left)
Make it fit around your pressure plate (like we did with the lights)
Look for Collision in your details panel
Make sure Generate Overlap Events is checked and Overlapalldynamic is selected in the presets
This makes anything that lands on top of the overlap will start an overlap event
Compile and Save
Under Events in the Box Details Panel, add the event On Component Begin Overlap
then select the box again and add the On Component End Overlap
(We have done this before)
**Important**
There is no Open Door Node in the Parent Class
We need to create a variable to deal with this
Create a new Variable and call it Door_Reference
In the details panel, change the variable type to BP Door Parent
Set it as an Object Reference
This will allow you to set a level instance of a door and set it as a reference
Make sure to make the instance editable by checking the box so we can select a door in the world
Compile and Save
Drag out your door reference and choose Get
From your Door Reference Node, pull out and add Open Door
Connect the Exec from the Begin Overlap to the Exec to the Open Door Node
Drag the Box Collision in the graph (Get)
Add Get Overlapping Actors
Click on Class Filter and select Actor
What we are doing here is making sure that any actor is the one closing the door and not something that happens to fall on the trigger
We are creating an array (list of actors that are overlapping)
From the overlapping actors node, pull out the blue output for overlapping actors and select Get (a copy)
Pull out from the Output of your Get and select Is Valid? MAKE SURE YOU USE THE ?
From the Exec of the End Overlap Box, connect to the input of the ? Is Valid Exec
Change the GET # to 1
This will ignore the Zero Result (character) and checks for the next actor (cube)
From our Door Reference Node, pull out an add Close Door
Connect the Is Not Valid Exec to the Exec Close Door
So if an actor overlaps (collides) with the box collision. the door opens and only the actor will close the door
Compile and save
Go back to your First Person Map and Drag a Door (BP_Door_Parent) in the game
Add a Pressure Plate and select it
In the Outliner Panel find Door Reference
Choose BP_Door_Parent
Compile, Save and Test
Now we are going to move the pressure plate and set the blocks so that they will open the pressure plate without the character
Move the pressure plate in front of the three stacked cubes
Select the cubes
In the outliner on the right, look for collision
Make sure Generate Overlap Events is selected
Make sure Collision Presets is set to PhysicActor
Compile, save and shoot the box on the pressure plate to open the door