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.