In the previous sections, we saw the basics of the Unreal Engine 4,
explained how the different types of lights work; we also saw the blocking,
the setting up of textures and decor. We built our first scene.
Now to complete this, we will see what Blueprints are, we saw before
that it is a scripting system that allows to develop without having to use
pure C++ directly.
With blueprints, you simply connect the different elements to each
other to make them interact with each other.
Creation of our first Blueprint
To better understand what it is, we will tackle this piece and do
ours. We're going to make a nice sliding door, which will open when our
character approaches it! Wonderful.
First of all, we will place a glass on our door, and adjust it to
cover the empty surface, like this, you know how to do it:
We have our window, it will slide when we approach it and close when
we move away.
We will first go to the "Modes" tab on the left, then to "Basic",
and select a "Box Trigger", place it at the door level, and adjust it so
that it is the area that will trigger the script that will open and close
We will also make our window "Movable" so that it can move around
the game, otherwise no interaction will be possible. Click on the window,
then in "Details", click on "Movable":
Now select your "Trigger Box" to be able to use it easily and click
on "Blueprints" at the top of the page, then on "Open Level
You are on the page that allows you to create your blueprints to
make the elements interact with each other, it is empty for the moment. We
will add our "Trigger Box" to it. Right click in the middle, then "Add
Event for Trigger Box 1" then "collision" and finally "Add On Actor Begin
Overlap", here is what it looks like:
Do the same thing again and this time add Add On Actor End Overlap".
This will be the beginning and end of our loop.
We want the window to move from right to left, in about 1 second, so
we will add a "Timeline"; by right-clicking again, scroll down and click
We want the door to open when we approach it, and close when we move
away, so we want it to do the opposite. So let's do the following:
Here we have therefore linked the beginning of our action (Begin
Overlap) with "Play", and the end of our action (End Overlap) with
"Reverse" so that it has the opposite effect and returns to its initial
position (door closed).
Now we will modify our Timeline so that the door opens and closes in
1 or 2 seconds. Double click on your timeline, it sends you to another
page. Here, add a "Vector Track" by clicking on the "V+" button at the top
of the page and name it as you wish. I have named it
The door will only move on the Y axis on my side (from left to right
and vice versa in relation to the orientation of my door); with you it can
be on the X axis, it is up to you to see how you have positioned your
We will therefore hide the X and Z axes to avoid making mistakes. To
do this, click on the eye near X and Y. Do "Shift" + left click on the
green Y axis to select it and be able to modify it. When you are at 0 for
time and value, redo "shift" + left click elsewhere and set 1.2 seconds
for time and 110 for value for the second yellow dot.
Concerning the value of time, it is the time we want for our door to
open, so we will take 1.2 seconds for our example.
Here is the result of our "Timeline":
We are done with the "Timeline". The door will therefore start to
open at time t=0 and end its sliding at time t=1.2 second. And we have
specified that this will influence the X axis, so it will slide from right
to left or the other way around; that's what we're going to add
Then we will go back to our "Event Graph", and add an event that
will launch the beginning of the action; for that do a right click then
type in the search bar "event begin play" and click on it to add it
Now, make sure that your "door" is selected on the game engine, then
come back to the Event Graph; On my side the door is a window, it will be
it that will open: its name is "SM_GlassWindow3". We will add it by
committing for the begin play event, so right-clicking and clicking on
"Create a reference to SM_GlassWindow3".
Now that you have understood the principle, we will move faster, do
the same by adding "Get Actor Location" and then connect your door to
"Target" so that it will be the target of the value change. Then, hold
down the click on "Return Value" and right-click on the blank, and click
on "Promote to variable"; like this:
You are asked to enter a name for your variable, it is important to
find your way around. We will name it "InitialDoorLocation":
Now let's connect our "Event BeginPlay" to the white pine of the
variable we just created. Then we will copy and paste your door down.
Let's take the pin blue by clicking on it and then right-click, type "set
actor location" and click on it".
Let's connect the "update" pin of your timeline to the white pin of
"set actor location" that you just added. This will cause the position of
the door to change over time; it will change at any time from t=0 to t=1.2
seconds as we have specified in the timeline.
Now let's add our variable "InitialDoorLocation" by doing "ctrl" +
hold click and drag it, like this:
Let's now click on the yellow pin of our variable, and right-click
to add our vector "vector + vector"; then connect the pin "Movement Door"
of our timeline, to the pin of the coordinates of our vector.
Let's now link our yellow pine from our vector to "New location" of
"Set Actor Location". This is what our blueprint level gives for the
As you can see, I always try not to cross the lines, so that the
blueptint always remains clear. Here it is not very long, but sometimes we
can have maybe 5 or 10 more elements, and that is where it can become
difficult to find your way around, if you are not organized.
Here we are, we have finished our Level Blueprint, it is time to
test it! First of all we need to compile it, you can do it by clicking on
"Compile" at the top left.
We can now go back to our level, play to test; let's see what it
At this point, I'm out of the trigger box, so the script doesn't
start. I'm going to go ahead and enter it to see the result.
That's it! our door opens from right to left, exactly as planned,
and in 1.2 seconds; you have to test it at home to see.