Realistic Basics Using Unreal Engine Blueprints
GCC Academy
Hello
I am Tak Gwang-wook, in charge of the Blueprint lecture
This time, we will create a simple function
using Blueprint
In this session, we will learn about the series of methods
for designing a function through a practical example
verifying whether the designed work works properly
and finally completing the function
Role and Mechanism of Collision
This time, I will create a simple function
using the basic blueprint theorywe learned earlier
The function is as follows: There is a white platform
When the player steps on this white platform
this white platform becomes a button
that opens the door in front of it
To do this, we need to prepare a few things
First, I think we need to install the door
We'll use the asset in StarterContent for the door
In the Content Drawer
you will see a folder called StarterContent
This is included when you create a project
and you can set
whether to install it
If you don't have it and didn't set it
then click this + button, and at the top
you will see an item called
Add Feature or Content Pack
If you click this item, you can add
various content items
Among them, there is an item called Content
If you look here, you will see Starter Content
If you select this Starter Content
and click Add to Project
the StarterContent folder we saw earlier will be created
and you can use various assets inside it
If you look inside, there is an item called Props
You will see various assets
Among them, you will see an asset called SM_Door
Let's try placing the assets
We want to put a platform in the middle here
and when the player presses this platform
we're going to make it rotate on the Z axis like this
When we press the play button, if we play like this
the character doesn't come out like this
It can only move around like this
We want to control the character directly
and have the character press the button
but since the character doesn't come out right now
we need to install a system that makes the character come out
It comes out like this because it wasn't created
in third-person mode when it was first created
so this system wasn't automatically installed
To do that, first cancel
and click the Add button
at the top of the Content Drawer
and then click Add Feature or Content Pack
You've clicked on our content a little while ago
Here, the Blueprint items
are organized in a way that allows you
to install multiple modes
Even if we didn't select this
before creating the project
we don't have to create the project again
We can add them additionally like this
We can simply click on Third Person
and Add to Project
and you can see that it is installed like this
The Content Browser pops up separately
Close it again
and click on Content Drawer
Now, several folders will be created
A Characters folder, LevelPrototyping
and a folder called Third Person will be created
This way, it's not applied right away
when you play
You need to make some settings
If you go to Edit, Project Settings
and look on the left, you'll see Maps&Modes
in the project items
You can change this mode
in the Maps&Modes item
Here, you can change it to the Third Person mode
we received
Click GameModeBase
If you look at the top
there's an item called BP_ThirdPersonGameMode
If you select this item
you'll see that the ones below
will be applied automatically
If this is applied
if you close the Project Settings window
and play again
the character will appear like this
The point where the character appears
is marked with this flag
This is an actor called PlayerStart
and this actor
specifies where
the character appears
So when you play
the character appears here
If you move this PlayerStart location
to the back like this
when you play, you can see the character
created a little further back than that location
Then, you can see the character appear
a little bit away from the door
I think it's okay to put it a little bit further back
I'll put it a little bit further back
If you put it like this and play, you can see that
it starts a little bit further away
Now we're ready
The door and player are ready
so let's create a button blueprint that can open the door
Let's open Content Drawer again
and create it inside this BP folder
Right click, click Blueprint Class
This time, I will inherit the actor class
to place it at this level
So click on the actor
name it BP_Door
Double click to go into the blueprint
Again, this panel will be attached next to the level like this
and Basic is not needed, so let's close it
First, let's make the appearance a little simpler
First, to express that this is a button
on the floor
I will create a button using a simple box
It's not an actual button you press
but I think it's good to think of it
as a visual representation that says, "This is a stepping stone"
So, if you press the + button in Components
and search for Cube
you can pull out a cube shape like this
I'll click on it to pull out a cube
This is a component that gives it a cube-shaped appearance
It simply takes care of the appearance
And here, there's a Static Mesh
called Cube
which has a square shape like this
I will change this square shape a little bit and make it flat
If I make it flat like this, around 0.1 on the Z-axis
I'll make it flat like this, around 0.05
Let's make it flat like this
This will create a simple mark that
the character can step on
Next, the platform called the cube
is not directly pressed
I said it is not directly pressed
but it is just indicated as a location
where you can press
The concept that we move the character, stand on this platform
and press this platform
is actually because there is an area
that can detect a character
When the character enters that space and collides
when the overlap occurs
it can be seen as a pressed event
So, the important thing is that there needs to be an area
that the character can collide with
So, that area that can collide with the character
and cause the character to collide
This area is called
Collision
So we need to install Collision
Likewise, if you click the + button in Components
and search for Collision
you can pull out various types of Collisions
I'll choose Box Collision among them
I'll just name it Box
If you create a Box Collision component like this
you can see that a shape with
only a yellow wireframe is created
This means the area
It indicates the collision area
This area can be raised
using the size or scale
or there is an item called Box Extent below it
You can adjust the value using this Box Extent
Let's adjust it a little to fit the size
Let's set it to about 50
and 50, 50
Then, it will almost match the white box shape below
And let's install it above so that it doesn't go out
If you mark the area like this
when the character sees this white stepping stone and steps on it
the character overlaps this Collision Box
When it recognizes that the character has entered this area
the door will open based on that recognition
Then, the user will think that they pressed the stepping stone
So you can think of this area as a space that recognizes
that the character has entered this space
a detection space
That's Collision
First, let's put the appearance like this, compile it, save it
and install it here
I'll drag and drop the blueprint
from the Content Drawer and place it like this
When I place it like this, you can see that it is expressed
together with the white platform
and the yellow collision area
Then, when the character comes to
step on the platform
let's output "Detected" just like
we output "Hello World"
to check whether it is detected and works well
Go back to BP_Door
This time, we need to create an output function
so, we have to go to the Event Graph item at the top
Click Event Graph
First, Print String
Select
the Print String node
I'll set it to output "Detected"
in this Print String node
I'll set like this
Where should I connect this node?
Which event node should I connect it to?
When it starts? When it's alive? Or when it overlaps with an actor?
Of course, it's when it overlaps with an actor
This Collision that we created
is related to this ActorBeginOverlap
In other words, BeginOverlap, this node
tells this blueprint to generate
an event when it overlaps
with some external actor
How do you detect that there's an overlap?
That's the role of this box, Collision
When the Collision and the character overlap
that's when
ActorBeginOverlap occurs
and is executed
So if we connect the execution pin of
this ActorBeginOverlap to Print String like this
the Print String node will be executed
when the actor hits the Collision
Let's take a look
Compile, save, come back and play
As you can see now, there's a character like this
Let's go to this platform
When you go like this
do you see the phrase "Detected" appear in the upper left?
I'll make it a little longer
Let's make it 10 seconds, compile, save, play again
and move the character to the platform
Looking at the top left corner of the mask
you can see that it says Detected
That means
it's working properly
So now we can add some functions
to ActorBeginOverlap
Let's delete Print String
What are we going to do with this node?
We're going to rotate this door on this level to open it
Let's add a node
Right-click and select Add Actor World Rotation
Let's take this node out
This node rotates the actor
So, if you look, we need
two data pins on the left
One is who the target is
If we say self now, it means BP_Door itself
In other words, what I'm saying is that this thing itself will rotate
This platform itself will rotate
but we don't want that
So what we want is this door
so another actor
So, we will put this other actor in a variable
and connect that actor here
so that it can rotate
the external actor
So, we're going to create a variable first
In VARIABLES, press the + button
and name it Door
Since we need to put the external actor in a variable
the container that holds the actor, the data type, must be the Actor
I'll make a big choice for the classification and search for Actor here
Then, among the object types of Actor
there is an item called Object Reference in Actor
If you click on this item
it will be created as a variable containing the actor class
When we learned about data types
we said there are two types of actor data types
basic and user-defined data types
This actor data type belongs to the second
user-defined data type
In particular, this actor is a user data type created in Unreal
So, you can think of it as a class data type
created in advance to contain a class called Actor
Since we need to put a door in this variable from the outside
let's turn on the eye or check the Instance Editable item
to set it so that it can be pulled out
And this Door variable should now be connected here
We need to drag and drop it and click Get Door
to get the variable
Let's take this variable and connect
this variable to Target like this
Compile and save it, and let's take a look
Then, if you select this blueprint and look at the Details window
you can see a variable called Door in the middle
This Door doesn't contain anything right now
so you just need to assign this Door to this slot
You can do this by clicking the None sign
and selecting SM_Door directly
Or, you can click the clicker button on the right
directly select this object, and bring it in
Like this
Then you can see that it's been entered
So it's been selected like this
If you come back
you can see that this variable
now contains the Door actor
We're going to add a function
for that Door to rotate
If you look, there's an item here
The item below here controls
how much it will rotate
If you look, it says Delta Rotation
then X, Y, and Z
In other words, you can think of Delta as a variable value
Delta Rotation means, "How much will it rotate?"
"How much will it rotate?"
How much will it rotate on the X-axis, Y-axis
and how much will it rotate on the Z-axis
You can think of it as setting how much it will rotate
Here's the concept
If you select the Door actor
and look at Rotation, there are X, Y, and Z
You can think of it as specifying the angles of X, Y, and Z
As you can see, what we want is this
the arrows are X, Y, and Z
The gizmo is based on the world
Since we're going to rotate it based on the world
if you look at it based on the world
you'll see that it moves
based on the blue arrow Z-axis
So, you can add 90 degrees like this
Turn it back
and input 90 degrees only on the Z-axis
Since they're all combined now
I'd like to separate
the combined Input Pin
So, I'll right-click on the Input Pin
Then there's an item called Split Struct Pin
I'll select this
Then, you can see that it's separated into X, Y, and Z
X and Y will stay the same, and we want the Z-axis
We can input 90 degrees on the Z-axis like this
Then, we can connect it to
ActorBeginOverlap like this
Then, when the overlap occurs
it will rotate the Door actor
90 degrees on the Z-axis
Let's give it a try
Click Compile and Save
I came back and try to click Play
Wait
Right now, this door is probably not going to move
If you play, it won't move
The reason for this is because the properties of this mesh are set not to move
In other words, it's set to stationary, not moving
If you look in the Details window
and select this door in the Details window
there's an item called Mobility under Transform
This Mobility item is that
It should be checked as Static
What Static means is that
this actor is set never to move
You need to change this Static to Movable
Then, it will be able to move
If you press the play button in this state
there will be a character, and I'll go to the platform
If you step on the platform like this
you can see that it opens
But as you can see
when I play and press the platform
I don't like how it opens
I wish it would open smoothly
but it doesn't feel natural because it opens like this
So, we will make this node that we created
so that the door can open more smoothly
So how should we do that?
It would be good to rotate it little by little
in every frame
OK, then, let's connect this node to the tick
Maybe 90 degrees
Since it will rotate 90 degrees every frame
let's untie this
Since it will rotate 90 degrees every frame
it seems like it will rotate a lot
Let's make it move slowly
1 degree per frame
Let's see what happens I'll compile and save
If we play it
it looks like
it's working fine
It looks like it's working fine
but there's a problem here
You can see that the door is rotating
even though we haven't stepped on the platform
We want it to move when we step on the platform
It should move when we step on it, but it's moving even though we're not stepping on it
So, we need to add a little more functionality
We need to add a function to set whether or not
this character has stepped on this platform
Let's try this
In the blueprint, how do we tell
if we stepped on the button or the character
stepped on it?
I'm going to create a Boolean variable
I will create a container that can hold and be false
and when ActorBeginOverlap when there's a collision or when they stepped on it
we can change that variable to true
to indicate that it's open
We will make this Rotation node
operate based on the result
of that variable
So, first, we need to create a variable
So I will click the + button on VARIABLES
and name it isOpen
It's going to contain the information, "Is it open?"
So, I'm going to make the data type Boolean
There's no need to make this variable public
We just need to have the information inside
so I don't think it's necessary to open it
I'm going to deactivate
this basic value by compiling and saving
In other words, it's not open
it's notified that it's not open as deactivated
When ActorBeginOverlap is executed
that is, when a collision occurs, and an event occurs
we need to set it to check the isOpen variable like this
How do we do this? When we bring in the isOpen variable
we've only brought in Get isOpen so far
This time, we're going to select Set isOpen like this
So, we will connect the ActorBeginOverlap execution pin
to the Set execution pin
And we're going to check the isOpen of this Set node
Then, when the ActorBeginOverlap event occurs
that is, when the character collides with Collision, execute it
What kind of execution? Set the Set isOpen variable
How? I added a function to set it to check
Let's check if it's working properly
using the Print node
Let's put these guys down
and say
"It's open" here If it works properly
isOpen will be checked
and the phrase "It's open" will be printed
Let's check it out
Let's compile, save, play
and go to the platform
If we go to the platform like this and step on it, "It's open" will appear
Then, we can see that it's working properly
So what we need to do from now on is
Instead of continuing this function
that rotates the Add Actor World Rotation statement
in this event called Tick
we can add a function that says
Do this only when isOpen is true
depending on the situation of this isOpen variable
Now, let's add
a conditional expression
when this Tick event occurs
We learned about the node called Branch earlier
Branch
Using the Branch node
we connect the Branch from this Tick
Depending on the result of this conditional expression of this Branch
if it's true or false, we execute something
Our conditional expression is that when this isOpen
the variable becomes True and open
So, we drag and drop this variable
to Get isOpen
and connect it to this Condition like this
Then, if isOpen is true
the value contained in isOpen
if it's true, True
Iff it's true, the True execution pin
and if it's false, the False execution pin will be activated
When isOpen is true
what do we do when it's open? We said that it'll rotate
So, we can connect the True pin here like this
Easy, right? Since we don't have to do anything when it's False
I don't think we need to connect anything
Let's compile and save in this state and check it out
If you play, the door won't move in its current state
The reason is that the value of Is Open is False now
If you go to the platform
and make the isOpen variable true, it will move
Let's go
It opens
If you play again and have your character approach the platform
you can see that it moves like this
Okay? There's another problem here
You can see that the door keeps rotating
It should stop when it turns 90 degrees
If the Z value of this Door's Rotation value
is greater than 90 degrees, it should stop
Right? I'll do that here
While it's spinning
here we will create another conditional expression
Branch
Branch, what's the conditional expression?
If the Z value of the Door is greater than 90, right?
That is, this Door
I'll get the Door variable
Get Door, this Door is this Door
We're going to get the Rotation value
That is, we will get the Rotation Z value in the Transform
So we're going to pull it out like this
and among the properties, functions, or values ​​that this Door variable has
we're going to say, Get, get, what?
Actor Rotation
that is, get the rotation value of the actor
Then we've got the rotation value of this Door
That information is now stored here
Likewise, you can subtract the return value
but in this case, the values ​​are all X, Y, and Z
So, we only need to get the Z value here
So right-click here
and click Split Struct Pin
and it will be released right away
We only need to compare this value among these
So if this value, this Z value now is greater than 90 degrees
So right-click
Greater
Bring up the Greater comparison operator
And put this Z value above the comparison operator
elow this, you can decide how much it will be greater than
You can put a general number
but for now, you can just put
the number 90 here
Then, if this Z value is greater
than 90 degrees
it will be established like this
The result value is now connected
to this Branch like this
Then, if this result value is greater than 90 degrees, it should stop
It should stop
If the Z value of Door is greater than 90 degrees
it will proceed with the True value
At that time, we change the isOpen variable back to False
If we changed it
we said this Tick event would occur every frame
When it occurs again
is the isOpen variable inactive? Is it False?
Then, it will say that it should not go to True but to False
and will not do anything
In other words, it will stop
All of this will stop
So, I'm going to do this here
I will bring in the isOpen variable
and open the Set isOpen mode
So, when it's greater than 90 degrees when it's true
I will run it to deactivate the isOpen variable
That's what we did
Done?
Then, let's take a look again
Let's test it here
Let's print "It is now stopped"
through Print String
If this works well
isOpwen will be deactivated
and "It is stopped" will be printed
Then, it must have worked well
We'll know
Let's say "It is stopped"
about 10 times for a long time
Right now, "Open" and "It is opened"
are set to 2 seconds
so that it will disappear quickly, so let's set it to 10 seconds
If you compile, save, and play again
pressing a button like this
will stop with the message "It is opened"
This time, it's finished
After it's fully opened and over 90 degrees
you can see that "It is stopped" is printed
and the door naturally stops
Then, this time, I think the opening speed is a little slow
so I'll look for something suitable
Right now, it's 1
so let's create a variable
to modify it externally
So, I'll click on VARIABLES
and create a variable
I'll name it Speed
I'll make sure the value is Float and up to the decimal point
Then, I'll extract this variable with Get Speed ​​
​​and put the variable
into Delta Rotation like this
Click on Compile and Save
For now, we should set the default value for Speed ​​to 1
And I'll check Instance Editable
so that it can be modified externally
Click on Compile and Save This time, when you go outside
it's not this Door
and if you click on this Blueprint
the Blueprint we created, you can see that there are items
that can be set up to the Door Speed
It's currently at 1, but I'll make it faster
How about 10?
I'll play it when it's like this
If I go like this
it's too fast, right?
Let's just make it around 3
You'll see it open
if you play it
If you think it's too fast, you can decrease it further
You can even decrease it to 0.5
You'll see it open slowly like this
I adjusted the speed of the door
using the Speed ​​variable
So, I created a function so that a constant value
increases every frame
Delta Second
But this function has a fatal error
It is not an error at this point
on the PC you are playing on
However, learning about the delta second concept
will help you realize this mod has a huge error
Let's learn about delta second
First, let's say there are two PCs
Let's say that two players, Cheol-soo and Young-hee
are playing a racing game with two computers
This race game is designed so that
each frame reads 1 meter
Let's say Cheol-soo's computer is a bit better
so it takes 0.25 seconds to read one frame
And in the case of Young-hee's computer
if it takes 0.5 seconds
when 1 second passes, Cheol-soo's PC will have read 4 times
and every time it reads a frame, it will move 1 meter each
so that Cheol-soo will have moved 4 meters
Young-hee's PC will read two frames per second
Since it reads 0.5 seconds per frame
it will read 1m per frame
and 1m per frame
so as a result, it will move 2m
in 1 second
In other words, Yeong-hee will always lag behind Cheol-soo
This means that the result of the running game will differ
depending on whether the PC is good or bad
This will cause unfairness
So the method used is
right here, delta seconds
That is, the displacement time is applied
It multiplies the time to read one frame
and maintains it at a certain time
In other words, it forces the movement to be 1m
when 1 second has passed
So for each frame
Cheol-soo multiplies a fixed amount of time by a slightly smaller number, 0.25
and Young-hee's computer multiplies it by 0.5
which is a slightly different
Cheol-soo and Young-hee's computers multiply
slightly different amounts of time
In the end, these two players
can get the same result
of moving 1m in 1 second
Then, it won't be unfair to either of them
Multiplying this Speed ​​value by the value of the time
to read this frame, called delta seconds
fixes the overall time
This is the most basic element in programming
the most basic element
in creating real-time content
So I'm going to do that
So if you right-click in this blank space
and search for displacement time, Get World delta Seconds
this node will appear
This Delta Second is different for each PC
It varies depending on the situation
Since this is information that the engine calculates and sends
you can just take it and use it
So you need to multiply this Delta Seconds
by this Speed ​​value
So, Multiply
Multiply this Speed ​​value by this Delta Seconds
and connect this multiplied result
to Delta Rotation like this
This way, the fairness between devices will not be violated
Let's play
Now, if you press the pedal
it will probably not seem to be moving
but if you press F8 and come out
very slightly
You can see it keep going up
That means it is moving
The reason it's so small is because by multiplying by the delta second
the number moving per frame
has become very low
So now, we need to increase
this Speed ​​value a lot
It had become very low at 0.5
This time, I'll increase it a bit to around 10
If you play it
It's a bit faster than before
We need to go a bit faster
Let's put it at around 100
If you play it
the result is the same in that it opens when you step on the pedal
but to ensure fairness between devices
we applied something called delta second
which is different from the current system
So now, when you run this function on this PC or another
it will move the same way
So, I created a simple function
to open a door using blueprints
Thank you
Now, let's summarize what we learned
Role of Collision and How It Works Automatic Door Implement automatic door function that opens by rotating when you step on the step Drag SM_Door asset from StarterContent - Props and place it in the world
Create a BP folder - Create a BP_Door blueprint inheriting the Actor class and place it in the level
Blueprint Scripting Add a Cube component using the +Add component in the component window Add a Box Collision component for collision with the character
Testing collision detection using Print String node in [Event ActorBeginOverlap]
Set up the door rotation Use the Add Actor World Rotation node to operate Create a Door variable that contains the object to rotate and connect it to the Target input pin
Connect the Event Tick node to the Add Actor World Rotation node, then set the Delta Rotation Z value Create the isOpen variable, then select the Boolean data type
Connect the Event Tick node to the Add Actor World Rotation node, then set the Delta Rotation Z value Create the isOpen variable, then select the Bool
Set the isOpen variable to be activated when ActorBeginOverlap is executed Set the door to rotate only when the isOpen variable is True
Set the door to stop rotating when the Rotation Z value of SM_Door is greater than 90
Control door rotation speed Create a variable, name it Speed, and select Float data type
Drag the Speed ​​variable to the graph window, select Get Speed, and connect it to the Delta Rotation Z pin Enable Instance Editable to enable external modification
Delta Second Understanding Frames If the code moves a certain distance per frame, the distance will vary depending on the performance of the device
The game path will vary depending on the device specifications, which is unfair
Delta Second To ensure fairness between devices, apply the displacement time Delta Second, the time it takes to read 1 frame If you apply Delta Second, you can adjust it to move the same distance simultaneously
Apply Delta Seconds Create Get World delta Seconds node Create Multiply and connect Speed ​​and Get World Delta Seconds nodes
Connect Multiply result to Delta Rotation Z pin Check that the door rotation speed changes depending on the Speed ​​value