Variables - Part 1

Unreal Engine 4: Intro to Game Design Blueprint Scripting Fundamentals - (FOR BEGINNERS!!!)
11 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$99.99
List Price:  $139.99
You save:  $40
€95.97
List Price:  €134.37
You save:  €38.39
£79.80
List Price:  £111.73
You save:  £31.92
CA$139.82
List Price:  CA$195.75
You save:  CA$55.93
A$153.75
List Price:  A$215.26
You save:  A$61.51
S$134.64
List Price:  S$188.51
You save:  S$53.86
HK$778.36
List Price:  HK$1,089.74
You save:  HK$311.37
CHF 89.34
List Price:  CHF 125.09
You save:  CHF 35.74
NOK kr1,107.14
List Price:  NOK kr1,550.05
You save:  NOK kr442.90
DKK kr715.75
List Price:  DKK kr1,002.09
You save:  DKK kr286.33
NZ$171.37
List Price:  NZ$239.93
You save:  NZ$68.55
د.إ367.26
List Price:  د.إ514.18
You save:  د.إ146.92
৳11,945.63
List Price:  ৳16,724.36
You save:  ৳4,778.73
₹8,442.99
List Price:  ₹11,820.52
You save:  ₹3,377.53
RM446.75
List Price:  RM625.47
You save:  RM178.72
₦169,271.38
List Price:  ₦236,986.70
You save:  ₦67,715.32
₨27,777.22
List Price:  ₨38,889.22
You save:  ₨11,112
฿3,446.26
List Price:  ฿4,824.91
You save:  ฿1,378.64
₺3,454.90
List Price:  ₺4,837
You save:  ₺1,382.10
B$580.04
List Price:  B$812.08
You save:  B$232.04
R1,811.35
List Price:  R2,535.96
You save:  R724.61
Лв187.69
List Price:  Лв262.77
You save:  Лв75.08
₩140,436.95
List Price:  ₩196,617.35
You save:  ₩56,180.40
₪370.16
List Price:  ₪518.24
You save:  ₪148.08
₱5,893.31
List Price:  ₱8,250.87
You save:  ₱2,357.56
¥15,475.45
List Price:  ¥21,666.25
You save:  ¥6,190.80
MX$2,042.64
List Price:  MX$2,859.78
You save:  MX$817.14
QR364.56
List Price:  QR510.41
You save:  QR145.84
P1,367.06
List Price:  P1,913.94
You save:  P546.88
KSh12,945.58
List Price:  KSh18,124.33
You save:  KSh5,178.75
E£4,964.52
List Price:  E£6,950.52
You save:  E£1,986
ብር12,237.67
List Price:  ብር17,133.23
You save:  ብር4,895.55
Kz91,290.87
List Price:  Kz127,810.87
You save:  Kz36,520
CLP$98,658.13
List Price:  CLP$138,125.33
You save:  CLP$39,467.20
CN¥724.22
List Price:  CN¥1,013.94
You save:  CN¥289.72
RD$6,024.63
List Price:  RD$8,434.73
You save:  RD$2,410.09
DA13,426.15
List Price:  DA18,797.15
You save:  DA5,371
FJ$227.57
List Price:  FJ$318.61
You save:  FJ$91.03
Q771.64
List Price:  Q1,080.33
You save:  Q308.69
GY$20,913.50
List Price:  GY$29,279.73
You save:  GY$8,366.23
ISK kr13,966.60
List Price:  ISK kr19,553.80
You save:  ISK kr5,587.20
DH1,005.63
List Price:  DH1,407.93
You save:  DH402.29
L1,821.98
List Price:  L2,550.85
You save:  L728.86
ден5,904.20
List Price:  ден8,266.12
You save:  ден2,361.91
MOP$801.48
List Price:  MOP$1,122.11
You save:  MOP$320.62
N$1,812.81
List Price:  N$2,538.01
You save:  N$725.20
C$3,678.31
List Price:  C$5,149.78
You save:  C$1,471.47
रु13,500.25
List Price:  रु18,900.90
You save:  रु5,400.64
S/379.05
List Price:  S/530.69
You save:  S/151.63
K402.47
List Price:  K563.48
You save:  K161
SAR375.40
List Price:  SAR525.58
You save:  SAR150.17
ZK2,764.29
List Price:  ZK3,870.12
You save:  ZK1,105.82
L477.77
List Price:  L668.90
You save:  L191.12
Kč2,432.37
List Price:  Kč3,405.42
You save:  Kč973.04
Ft39,496.05
List Price:  Ft55,296.05
You save:  Ft15,800
SEK kr1,103.50
List Price:  SEK kr1,544.95
You save:  SEK kr441.44
ARS$100,374.93
List Price:  ARS$140,528.92
You save:  ARS$40,153.99
Bs690.75
List Price:  Bs967.07
You save:  Bs276.32
COP$438,931.09
List Price:  COP$614,521.09
You save:  COP$175,589.99
₡50,918.63
List Price:  ₡71,288.12
You save:  ₡20,369.49
L2,526.16
List Price:  L3,536.73
You save:  L1,010.56
₲780,388.98
List Price:  ₲1,092,575.79
You save:  ₲312,186.81
$U4,261.82
List Price:  $U5,966.72
You save:  $U1,704.90
zł416.31
List Price:  zł582.85
You save:  zł166.54
Already have an account? Log In

Transcript

Hi again and in this video tutorial we are going to be talking about variables in blueprint scripting. So let's start things off by defining what are variables? Well think of variables are containers that store information. So just as a Tupperware container stores food, or maybe a big plastic bin stores old clothes, variables are containers that store something as well they store information. And this information can be used to determine things about the game such as how many points something is worth, or maybe whether the player has the right key to unlock a door. So to help aid in this discussion, I'm going to be opening up two different blueprints right here.

I'm in the third person template and I've got a third person character located in content, third verse, Person B. PE blueprints gonna double click on this guy. And then I'm just gonna jump on back here to my main editor and I'm also going to access my Level Blueprint. So within any blueprint that you are working in, there is a section in this My Blueprint panel over here. For variables. This is where you can add variables to your game these containers that store information. So this is where they are located in your Level Blueprint.

And back over my third person Character Blueprint, My Blueprint panel is right here and this is the section four variables. Now, the my character blueprint that came with the third person template here already had a couple of variables here, by default. I've added another one here before the video started called my health. So this is a variable that I created that I want to store some information in this case, how many hit points I have and this variable is known as an integer variable, which is one of the different types of variables. An integer variable holds a whole number values. We'll talk about different variable types here in just a moment.

Before we get to creating some variables here, I just want to do a quick demonstration showing you that variables do in fact, hold some information. So I've got a quick setup here, I've got a reference to my health variable right here in my Event Graph. And I've also got an H key event. So when I press the H key event, something is going to happen. And in this case, I want to print something out to the screen. Right now if I was to press the H button, it would show this string this text hello to my screen.

But if I plug in my health variable into this string input, I'll get this little conversion node and this is actually going to convert this type of data which is known as integer data. into a string that can then be printed out to the screen. So think of a string and it's kind of a fancy word. Think of string is alphanumeric characters. So think of letters, numbers, symbols represent the string. So anyways, before I do this, I have my health variable selected right here in the graph.

And if you look over in the Details panel, you can see that I have a value associated with this the value of 100. So if I was to jump in the game right now and press the H key in the upper left hand corner of the screen, you will see that number 100 printed out. I'm just spamming pressing the H button right now, in case you cannot hear that. So that shows that it is reading it is getting, how much health in this case, a value of 100 is located within this variable. Okay, let's go Talk about different variable types right now. And to create a variable in any type of blueprint, you come under your variables category, and to the right here is this plus variable button.

So the first type of variable that we are going to create is called a boolean variable. So I'm just going to call this my bool. And by default, it is a of the Boolean type. This red color right here indicates that it is a Boolean type. And you can see that actually, if you take your mouse cursor and hover over it in the tooltip, it says the current type is Boolean. Now we're going to see when we create some more variables in just a moment here how to change these variable types.

So before I do that, though, I just want to demonstrate that my Boolean contains true or false information. That's what this variable type contains. So I need to assign a default value to If I look over my Details panel right now, it says I need to compile the blueprint in order to give it a default value. So I'm just going to click on the compile button right here. And this little checkbox here that is currently unchecked, represents a value of false. I can check it to make this be true.

So just to demonstrate this at work, I'm just going to drag in a copy of the my bool variable. And when I do I get a selection for if I want to get what is in there, or set the content of that container. In this case, I want to do a get and we'll plug that into the string input here, a little conversion node will appear. And now if I click on play, and press the H key, you will see that it reads false. Now if I go back to my bool, and check that box, jump in and play and I hit that he you can see that it reads true So there is a boolean variable that holds true or false information. I'm going to click on this plus variable button one more time.

And I am going to create a variable called my floats. Now float variables, unlike integer variables right here, hold a number, but it is a decimal point number. Right now I need to change this variable type. And there are two places that you can do that. The easiest way is you click on this little pill looking color right here, you can change the variable type right here to be a float. Alternate alternatively, with this variable selected over here in the Details panel on the right hand side, you could change the variable type as well.

So I'm just going to go ahead and get rid of my bool right here. I'm going to left click and drag this variable and I'm going to get it now, we can't get anything from this just yet because I have not given it a default value. You need to compile first. So let's Compile and let's give this a value of 5.5. So float values are oftentimes awesome to hold time values. For example, maybe you want something to happen like a door opening over the course of five and a half seconds.

So this gives you a very fine precise control over how many seconds for example, it would take to open something. All right, so I'm just going to plug this into the in string here, it's going to bring in that little conversion know that's going to convert a float variable into a string. And now if I hit play, and press that H key, you see that value of 5.5 shown again and again. Okay, the next variable I'm going to add clicking this little plus button right here is just going to be called my string. Hit enter here, I'm just gonna delete out this old stuff right here. And with my string selected, I'm going to click right here to Turn it into a string type of variable, which is this magenta color.

I'm going to compile so I can add a default value here. And I'm just gonna type in Hi 12345. And then maybe, let's do asterisk, exclamation point, question mark, like so. And I'm just going to left click and drag this into my Event Graph, and I'm going to say I want to get it and now I can plug this guy straight into my print string and there's going to be no conversion node that appears here because it is looking for a string variable type and this happens to be a string variable. So now if I could click on play, and press the H key, you can see what is read out of that there capsule, that variable. Okay, so that's a string variable.

Let's just delete this guy out. Next one I want to show is another commonly used one. gonna click this plus symbol and I'm going to call it my vector. And I'm going to change the type right here to be a vector. And I'm going to left click and drag this variable into my graph again, get my vector. And what I'm going to do is I'm going to plug this into here.

Now again, I need to give this a default value. So I'm just going to select my variable, compile. And you can see that my vector contains X, Y, and Z data. So this is great for locational data. Let's say for example, you want to spawn something in at a given location. Well, you can store that given location in a vector variable.

This would specify x, y and z coordinates within your world in which to make something happen, for example, spawn enemy. So right now I've got values of 000 in here. So if I just play and I press that H key, it's going to read the value You can see it reads it out is 000. Next, I want to point out the different ways that you can add variables to your graph. So the first way that you saw me do is I can simply left click and drag a variable from my my variable section over here into the graph, then you'll get a little pop up seeing if you want to get it or set it more on setting it in just a moment. So that's one way.

Another way is, and this is a shortcut way is you could hold down the Control key while you then left click and drag it in, and that will automatically get that variable. Yet another way that you could find this variable attitude graph is to simply right click in the graph in some empty space and simply type in my vector. And here you get a get my vector. So there are a few ways to add some variables to your graph.

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.