This is Kim Hyun-Jin, and I am teaching Unreal Engine Basics for Immersive Contents
In this chapter, we will learn about what Blueprints are
And what its basic grammars are
Blueprint Node: Structure and Flow
Let's create a new level
File, New Level, and select Basic
Create, and then save
Let's name it 'BlueprintLevel'
Make sure to save
At our Content Browser, select our Content folder
And we see all these files we created
Let's make some folders to organize them
Click on Add, and select New Folder
Let's name it 'Space Design Level''
And select all the files we used for space design
And drag everything into that folder
And we get this option; select 'move here'
And all the files move just like so
And let's double click our Space Design Level
And we go to that level where we did the space design
And when we click on this Blueprint Level
Then we move to this basic level
Let's create another folder
You can also right click on Content Browser to do so
Select New Folder, and let's name is Blueprint Level
And let's drag this Blueprint Level to move
Double click on this folder, Blueprint Level
And right click
And let's create a Blueprint Class
Click
And we get this winddow
Here we choose what we are going to make our Blueprint Class out of
Meaning, we are choosing what would be its parent
Let's choose Actor as the parent
So choose Actor
Let's name it 'BlueprintStudy'
Double click to open the file, and you get this Blueprint window
We get Viewport, Constructor Script and Event Graph tabs
Here, choose Event Graph tab
And we get these nodes already created
These are called Blueprint Nodes
Right click and let's type 'print' to search
And we get this menu called Print String
Click on that
And that adds a node called Print String
And now, go to this node called Event Begin Play
Hover the cursor over this triangular icon
And drag it out to have this line out
And as you drag it to this triangular shape at Blueprint String
This dropdown will connect the two
And now, click on 'Compile' on your top left
And press 'Save'
What does 'Compile' do?
We just added a node
And by compiling, we let the computer know that this should work well
So whenever we change something
Always press 'Compile' afterwards
And inside Print String, here at 'In String'
It says 'Hello'
And let's click on it
And change it to 'Hello World'
Since we just changed this part, we should compile again
See this question mark?
This means that we should compile now
So click on it, and when it becomes a blue tick mark, it means it succeeded
Now, back to our Blueprint Level
And let's drag out this BlueprintStudy to place it here
I told you that only actors can be on this level, right?
And what was the parent when we created this Blueprint?
We chose 'Actor', remember?
That means that this BlueprintStudy is an actor
That's why we can place it here
So now let's finally press on 'Run'
And we just saw 'Hello World' to our top left
Let's stop and press 'Play'
And it prints 'Hello World'
Next to Content Drawer, there is a menu called Output Log
Let's go to that menu
And at this first class for BlueprintStudy
It has printed 'Hello World'
That's the message we see printed here as well
We will be using that Output Log Window often as well
So let's just pin it here, like this Content Browser
So go to Window, and Output Log
Click on the menu and it goes next to our Content Browser
So we can go back and forth these tabs
Let's now create another Print String
Click on the node, Ctrl C and Ctrl V to copy and paste
Now, let's connect this node called Event Tick to Print String
Let's change the content, let's call it 'Unreal Engine'
And then Compile, come back to Blueprint level
And 'Play'
Now we see a lot of 'Unreal Engine'
It keeps printing
Let's stop
Let's play and then stop right away
I pressed 'Play' and stopped right away
Then, at Output Log, we only see one 'Hello World'
And this repeating 'Unreal Engine'
And here, we can see that
Begin Play is something that is called only once when run
And then for Event Tick, it is something
That is called in repeatedly after it runs
And when we want to disconnect this
While pressing Alt, hover the cursor over the line
And left click to make it disappear
Let's now move this Print String node that says 'Unreal Engine'
And after this Print String with 'Hello World' runs
Let's connect it like so
So the order is, Begin Play runs
And moving over, Print String runs
And then, also moving over
This Print String for 'Unreal Engine' runs
So let's play at our Blueprint level
In this Output Log, it says 'Hello World' runs first
And then 'Unreal Engine' runs afterwards
So this pin on the top is called the 'Execution Pin'
So this visualizes the order in which the nodes are run
And the content inside is called 'Input Pin'
It takes a data input and holds that value
Using Variables
Now, let's try using some variables
Before that, what is a variable?
Variable is a bowl that holds data
But for a variable, we need to specify it to hold only some kinds of data
And what does that is data type
So variable and data type are like a pair
And today we will talk about around four data types
First is int data type
Int makes a variable to hold integers
Meaning, to hold numbers
Natural numbers like 1, 2, 3, 4
Or 0 as well
And also negative numbers like -1, -2, -3 are in this data type
Float allows for real numbers
This allows for any decimal points as well
So this includes what int includes as well
But it also allows for real numbers, such as decimal points as well
Now, bool type can only hold two things
True or False
So it is always either True or False
String is for text values
Let's now practice with these basic four data types
To the left, we see My Blueprint window
And there is a tab called VARIABLES
And see the plus icon there?
Click on the plus button
And this creates a variable
The first tab sets the variable name
And the second, try the dropdown menu for Boolean
And we get to choose the data type
There are a lot of types
But today, we will just test the basic four
For now, Boolean is the default data type
So let's start with this and see how this works
Let's rename it as well
You can either click on its name part or press F2 to rename it
Or you can select that variable and move to the right at 'Details'
And this shows what the name is and what its data type is as well
You can rename this here as well
Let's name it as 'isbool'
Now, to the left, under VARIABLES
The name of our variable changed into 'isbool' here as well
Now, when we compile it
Under Details, we get a tab called Default Value
And here is 'is Bool' and a checkbox
And this default value here is False
And if we tick it, the default value is True
So based on what the default value
For your variable should be
You can modify this part
Here, I made its default value True
And let's go ahead and check if our variable says True
So drag this variable into Event Graph
And it asks if you're bringing in the value in the bowl
Or if you're setting that value in this bowl
You are to choose between the two
For now, we are just checking what the value is
So let's click on 'get isBool'
And add a node that looks like this
Now, hover over this red pin of the node
Drag it out and connect it to this 'In String'
And this converts this bool type to a string type so that it prints
For this 'Unreal Engine' part, let's select and delete
Let's compile and come back to Blueprint level to run
Now we see 'True' here
So we now know that it starts with 'True'
Let's drag in isBool again
And this time let's bring in a node through this menu, 'set isBool'
This means that this Execution Pin will set the value of this 'isBool' when it is run
Since it is not ticked here, it means that isBool is set as False
So click on this Execution Pin while pressing Alt to disconnect
Let's say, when Begin Play starts, it starts setting
For the value of isBool
And then it will print it, that's how we changed a bit
Then, before this set-node runs, is-bool will be True
But here, as set-node runs, is-bool changes to False
And this parts asks for printing the value of is-bool
Because we changes it into False here
It will be printing False
Let's compile and play
And we see 'False' as what is printed here
Let's create another variable with this plus button
Let's now name it 'intVar'
And then, at the dropdown menu from Boolean
Let's choose 'Integer' for int
IntVar means this data type is integer
So compile again, select intVar
And at Details, we can also set its default value
Now, it is set as 0
So if I set it as 100
As we run everything, this will start with 100
So let's drag in this intVar from the left
And let's use get intVar to bring in a node
And right click, search for Print String
And add a Print String node
And next to this bool type Print String
Let's connect this newly added Print String node
And this In String value
Let's set it so that this value is printed as what our variable holds
Let's re-organize the nodes
Now, compile and back to our Blueprint level to run
Now we see this value 100
It disappears right away at Viewport, so it may be easier to check at Output Log
So 'False' is printed first
And then we see this value '100' printed
Let's continue with float and string type variables
So VARIABLES, click on the plus button
Name it 'floatVar'
And from the dropdown menu, choose 'Float'
And add another, name it 'stringVar'
Click on what it says 'float' now
To choose the menu that says 'string'
And now let's compile
Select floatVar, and at Details
Let's set its default value as a decimal number, 3.14
And for our stringVar
Let's say its default value as 'Unreal Engine'
And let's print everything in these variables as well
So select this Print String node, Ctrl C and Ctrl V
Add another to have four in total
Drag in floatVar and bring it with 'get'
And let's connect In String so that it prints
Same thing with stringVar, drag and 'get'
And connect to In String
And it only runs when we connect the Execution Pins
If this is not connected, the nodes at the back will not run
So connect, connect
And compile, and now let's play
We see float 100 3.14 Unreal Engine, all the values in our variables
They are all printed like so
So based on data type, these variables here
Can hold different data values
Using If Statements
Let's try an if statement now
To an empty area at Event Graph, right click
And search for 'branch'
Of you can search for 'if'
And we get 'Branch'
Let's add this node that looks like this
This Branch Node is an Execution Pin, and when connected
When this node runs, based on the value in condition,
It branches between 'true' and 'false'
So let's say the condition is 'false' now
Then it runs an Execution Node over at this 'false' branch
Anything under this 'true' will not run
Let's say it is set as 'true'
Then anything after 'true' will run
Let's see how it actually works
Let's drag in our isBool and 'get'
And we can add this data like so
It's because they are the same bool types
Now, according to the value in here, it will say either True or False
Right click to add another Print String node
Copy and paste another under here
This will make this to run when True and this when False
Let's say here 'it is true'
And here, 'it is false'
Now, for isBool, when we begin
Since it is set as False
This is by default False, which will print this
Compile and play at our Blueprint level
And at Output Log it says 'it is false'
Then, when we start with Begin Play, we set isBool as True
Then, when we compile and play at Blueprint level
Now we see 'it is true' as what is printed
Like so, an if statement
Branches out based on whether this value in the condition is true or false
Now let's add a value to the condition in a different way
Let's delete isBool
Let's drag in our intVar variable from the left
And let's create another variable in int type
VARIABLES, click on the plus button
Let's name it 'intVar2'
And its data type is again an integer
Compile, and for Default Value, let's say 200
Now, drag in our intVar2 to bring it in
And drag the Execution Pin at our intVar node
And this allows for us to search
And here, try typing this sign
What do you call this? This is angle bracket from our math class
This asks whether the left value is bigger than the right
So it poses a question
And when we search for this, we get two nodes
The one that asks whether the left one is bigger
And the one that asks whether the left one is bigger or equal to the right
So let's go with this 'Greater'
And we get this node that looks like this
And let's drag in our intVar2 to connect it to the second pin
Now, intVar has the value 100
And intVar2 has the value 200
So here we ask, is this condition true or false?
This is false
So we get the value 'false' here
And if intVar2 is 50, instead of 200
It will ask if 100 is bigger than 50
And for that, the value here is true, not false
So this node uses these two values
To decide whether it is true based on this condition
So let's connect this value to this condition
This is connecting the result of the comparison, of these two values, to the condition
So if it is true
Then this part says 'var1 is bigger than var2'
And here, 'var1 is smaller than var2'
Let's modify that text
Let's compile
Come back to Blueprint level to play
And we get 'var1 is smaller than var2' printed here
The reason is, now var1 has 100
And var2 has 200 as their values
And this is what an if statement looks like
As we use more nodes, things may get more complex
And there are ways to group them
So let's drag all these to select them
And press 'C'
And we get a window where we can add a comment
Here, let's say 'Variable Practice'
And here too, let's drag this part and press 'C'
'If Statement Practice'
Using this comment function
You can group the nodes
And when you move it around, dragging on this white area
All the nodes in this area will move altogether
So when you are implementing per method
This is a good habit to have, to group them together like so
Using Functions
This time, let's try using some functions
First, get intVar from the left with 'get'
And intVar2 again with 'get'
For intVar, drag it out like so
And let's search for plus
And we get 'add' like so
Click on 'add'
And this looks very similar to our if statement node
But this part says plus
And its Output Pin has a different color
Let's drag this IntVar2 to connect to the second pin
This obviously means that it will deliver the value, which is the sum
And let's now print this result here
Right click, add a Print String node
And let's connect this printed value from In String
To print that value
And as of now, this node will not run
Why not?
It's because the Execution Pin is not connected yet
So for now, let's disconnect this Variable and If Statement Practices
Starting with Begin Play
Press Alt and disconnect
Let's instead connect it to this part
At Blueprint
We often have the line overlap with other nodes
If that's fine with you, this won't do any harm
But a helpful way of organizing this is
To double click on this line
Then it adds a pin like that
And you can adjust the shape and location by dragging this part
This way, the line does not overlap with the node over there
We can organize the visuals for the nodes like so
Compile and play at Blueprint level
We see the value 300, which is the sum of 100 and 200
Let's stop it
And let's repeat this same action once more
How do we do that?
Copy everything
And paste
And connect these two
And how do we do it yet again?
Copy and paste again
If we use copy and paste in order to repeat an action
This screen will look incredibly complex
That's when we start using a function
So let's delete what we just added here
Let me change this part using a function
At My Blueprint, we have FUNCTIONS tab
Click on the plus button here to create a function
Let's click on the plus button
Now we name this function
Let's say 'Plus'
When we have a function
We get another window next to Event Graph
This is a window designated for functions
This part for Event Graph
Where two values are added, copy this part
And move to Plus tab and paste
Then the nodes move like so
So when this function Plus runs
We are connecting this to say 'run this'
Back to Event Graph
Let's now delete this part
Let's drag our Plus function here
And we get a node
And we can connect our Execution Pin
Compile, play at Blueprint level
And we get that same 300
As it starts with Begin Play
It is running our function, Plus
And what happens there? It goes in here
And it runs everything attached here
And what is it?
It is where we print the sum of the two values
Let's say we are repeating this same action
Then we can simply connect this Plus node again
And this looks much more intuitive than before
This is the basic structure of a function
When we run a function
It just does an action inside, of adding 100 and 200
Meaning, the value in IntVar
And the value in IntVar2, summing them and printing the result
When we think of a calculator
A calculator shows us the result of adding two numbers
Same with this Plus function; it uses the two values, sums them up
And prints the result
And this is called a parameter
Double click on this Plus function to open it
And click on this Plus node
Over at Details, we get Inputs
And click on this plus button
And this looks like the variable that we created
Let's name it num1
And click on where it says Boolean to change it into integer, and let's add another
The name will be num2, an int type
So here, for our Plus node
It used to not have these pins called num1 and num2
And now it does
So let's delete this intVar and intVar2
Let's instead use the values as inputs through variables
To sum them up and then print the result, whenever Plus runs
So over at Event Graph
Now this Plus node has changed, where we can add something
Here, drag in intVar
And intVar2 to connect each here
Now, with Begin Play, this Plus function runs
And when it does, the values in intVar and intVar2
They move into num1 and num2, respectively
And then over at this Plus function
num1 has 100
And num2 has 200
Let's copy and paste Plus
And let's write the value directly here
Let's say, we're adding 50 and 1000
And connect this Execution Pin
And now
Here, this adds the values from intVar and intVar2
And here, it adds 50 and 1000
Compile, play at Blueprint level
And we get 300 and 1050 as what is printed
Now, for the sum of the two values
We'd like to add yet another value to that, like 50
Then, this Plus function will now provide
A result value of that summation
So let's modify this function
To the left, at FUNCTIONS, double click on our function Plus to open
And choose this Plus node
And to the right, at Details, we now get Outputs
Click on the plus button here
And let's name it 'Result'
Data type, int again
Now we get this Return node
And here, remove Print String
And remove this node where we change int type to string
Now, we will move right from Plus node to Return node
For Result, let's add the result of summing num1 and num2
And then back at Event Graph
We now have a value called Result below the Plus button's Exec Pin
Here it has 100 and here 200
So now Result has the value 300
Now, this value can connect to num1
And for num2, let's say 1000
So what will happen here?
300 and 1000 will add up
And for this result, we will get 1300
Let's see if it works that way
Right click and Print String
And let's connect this result to In String to print
Compile
And play here
We get this value 1300 printed here
So we just worked on the three types of function
First, we began simple; this function has no inputs or outputs
Second, the function now had inputs
And third, the function had both inputs and outputs
Using Iterations
Now let's try iterations
On any empty surface, right click and search 'for loop'
And we get 'for loop' at the bottom
Select this, and we get this node
For First Index, add 0, and Last Index, 10
And right click to add a Print String node
And for this Loop Body Exec Pin, connect Print String
And using this Index, connect it to In String
And add another Print String node
And at Completed Exec Pin, connect another Print String
And let's say 'Iteration complete' here
So at the end of this Exec Pin, of the last Print String we used for our function practice
Let's bring it in and connect to our For Loop
And double click on this line to add a pin
Just to tidy it up visually
And let's compile and play at Blueprint level
And what happens?
It prints numbers from 0 to 10
ANd at the end it says 'Iteration complete'
So this node starts with the value 0
And when Loop Body runs once
This Index has the value 0 in it
That's why it prints 0
And it repeats until 0 becomes 10
How? By incrementing by one
So one incrementation from 0 becomes 1
So Index now is 1, which prints 1
When it becomes 2, it prints 2
3, 4, 5, 6, 7, 8, 9 and up until 10
And after printing 10, it stops
And when it repeats until that final loop
This 'Completed' runs
And it prints what we added, 'Iteration complete'
Let's apply this to create a times table
For a times table, we need to multiply from 1 to 9
2x1=2, 2x2=4, 2x3=6 and so on
Let's remove this node that connects to In String for now
So Index will change from 1 to 9, incrementing by one
So let's search for 'x' for multiplication
And we get 'Multiply'
Let's create that Multiply node
And let's add the value 5 here
Then, it brings in that value 1, multiplies by 5
And what does it get? 5
So it prints that value
And what about when this becomes from 1 to 2?
The result is 10, and when this is 3, it is 15
This will be the 5 times table
Compile, play at Blueprint level
Just like that, 5, 10, 15, 20
We get the result for a 5 times table
We have learned about variables, if statements, functions and iterations
These are the basic grammars for Blueprint
So I highly recommend that you take some time
To try and go over these concepts multiple times on your own
Let's summarize what we've learned in this chapter
We learned about the structure and the flow of Blueprint
And we learned about basic grammar of Blueprint: variable, function, if statement and iteration
Blueprint Node: Structure and Flow Creating Blueprint Class What should its base be?
Add Print String nodes, Compile to check if it can run Select node, Ctrl C and Ctrl V to copy and create more
Node-related Terms Begin Play: Call once after run Event Tick: Call repeatedly after run Execute Pin: Order of nodes when run Input Pin: What contains the data input value
Using Variables Creating Variables My Blueprint - VARIABLES - ( ) icon
Data type Int Float Bool String Distinguish its value and setup to select
Using If Statements Creating Branch Nodes When running a node, it branches to either True or False based on the value for the condition Search for 'Branch' or 'If' at Event Graph
Using Functions Creating Functions Functions: command for the nodes with the same action My Blueprint - Functions - ( ) button
Parameter Which receives two values, adds them and prints the result Details - Inputs - ( ) button
Return Node Creating Return Value Details - Outputs - ( ) button, choose Integer data type
Using Iterations Creating Iteration Node Search for 'for loop'