Now up until this point, you've only seen me get or retrieve the information stored within these variables. The next thing I'm going to show you how to do is how to set the contents of these variables, it's really simple to do. If you were to right click any of these or sorry, left click and drag any of these variables into the graph, you can see that you have an option to set that variable. I'm going to do that here real quick. And I'm also going to left click and drag in what we call a getter. So this is short for a getter, I'm just going to right click and put that as a node comment.
This is known as a getter and this is known as a setter. So out of this node, we can get the information inside out This note right here, we can set the information inside. So you've already seen me plug this into the in string, so we can get the value of this variable right here, which is 100. But we can also set or change that number. So it doesn't have to be 100, we can actually change it. So this is what I'm going to do is on the pressing of the H key event, we're going to read what is the value of this variable.
And by default, here, it's going to be 100. Then when I release the H key, I'm going to set my health to be half of that. So I'm going to change the value here, I'm gonna change it to be 50. So what's going to happen here is I'm going to play and the first time I press the H key, you're going to see the value of 100. Now since I've just released the H key, I've now set the value of that variable to be 50. So now when I press the H key again, it's gonna read in 50 So know that whatever value is contained, whatever information is stored within a variable, it can be changed.
And that goes for any of these different variable types. So you can either get that variable, or you can set it. And the shortcut for placing this note out here is to simply hold the Alt key, left click and drag, and that'll bring you on a setter for any of the different variables you have. Some other things to know about variables here is that you can categorize them over here on the left hand side for, I guess, organizational purposes. So let me just delete out these nodes right here to clean up my graph here a little bit and make this all a little bit more readable. I don't like to have too much stuff in the middle here distracting me.
If I select my health variable over here. I can give this a category so let me just create a category called my variables. Enter. As soon as I do, you can see I've created a new category called my variables in my health is located under that. So what I can do then is I can click on my bool right here and add that to that category that I've just created of my variables. You can see that's now added my float, I can add that to my own category of my variables right here.
Same with string, it's cetera. Another good thing to note here is that you can reorganize how your variables are organized here, on the left hand side, you can drag and drop, say my string, move it right here, you'll see it will reorder my string before my health. So if you want to order all your different variables, say all your float variables to be ordered right next to one another, you can do that. Other things to note here about variables is you can set them To be public or private, let me show you what that means here a little bit. So with my float variable selected right here, I am going to make this publicly editable. So what I can do here is click on this little icon right here that shows a little eyeball.
And when you see this, I'm going to Compile and Save. I'm going to jump back to my level. And now if I was to drag and drop my third person character, in my level, there is over in the Details panel, you can see I've got a category called my float, which I can now edit straight away from the editor right here as opposed to going into my third person Character Blueprint. So this is a really handy way of exposing variables right in the editor to be easily modifiable. So again, because I clicked on this little icon right here showing that little eyeball. I alternatively could have checked this instance editable or editable checkbox right here.
That will make it so that the this particular variable is publicly editable. I can do the same thing with my health. Let me just click on my health in this time when we click on instance, editable right here, when I do, that eyeball icon becomes exposed. And you can see back here Whoops, I need to Compile and Save, always Compile and Save. You can see that both of these variables are now editable, right here in the main editor. variables can also be made private.
And when you make private variable, that means that if you make a child of any blueprint, those variables will not be inherited, or derived from the original blueprint. Now, that's kind of a big concept to digest here. So let's just say that we were to make a child of This third person Character Blueprint, you can right click on them. And we can create a child blueprint now just as children inherit properties from their own parents. So to do children blueprints inherit from their parents. So if I double click on this guy to open them up here, just gonna dock them along the top.
Over here on the right hand side in the Details panel with my class defaults button selected over here, I can see my various variables here, my string, my health, my float my bool. These correspond to my string, my health, my float my bool. Right. Now let's say for example, I wanted to make my bool be private. So I'm just going to click this checkbox right here. Get a Compile and Save.
And I'm going to go back here and I'm going to delete my original child here. I'm going to delete this Sky. Okay. So now if I go to create a child from that blueprint, double click on this guy to open them up. You can see that over in the Details panel with the class defaults button selected. The bool variable that I have on my parents is not available on my child blueprint.
So that is good to know. So public and private variable, I'm going to go ahead and delete this one for the time being. Delete that out. Just a couple more tidbits regarding variables before we wrap this up. In general, it is good practice to create variables where they make the most sense so jumping back to my third person character here for just a moment. You'll remember that we created this my health variable within our third person Character Blueprint because we want our character to have hit points.
If I jump over to my Level Blueprint blueprints Level Blueprint, you can see that this variable called my health that existed back on my third person character does not exist within my Level Blueprint. And in fact, if I did a search for my health, I'm not going to find it because this variable lives within this class, this third person character class blueprint. Okay? Could you create a variable called my health and stored in the Level Blueprint? Sure, you could do that but it makes more sense to have it on my character. So create your variables wherever they make most sense for your project.
A couple other tidbits of information you can delete out variables whenever you want. So if I did not want my bool here anymore, I could simply click Delete to delete it out. You can read Name your variables. So if I wanted to change my float to something else, I could click on that one time, click on it a second time, or simply click f2 while you have it highlighted, and I could call this my super float. You can also rename your selected variables up over here with the variable name. You can also change a variables type However, if you attempt to do this, you will receive a warning and potentially break some scripts in the process.
For example, I've got this my health node hooked up right here, this might help variable i could In the Details panel over here, select it and click right here to try to change the variable type. So if I tried to change it to a float, I'm going to get a warning saying hey, this could break connections Do you want to search all variable my help instances change the type and recompile I don't want to do this but in Note that you can create problems with your script if you decide to change a variables type, especially when you have it hooked up to many functions. Alright, that is pretty much going to do it for this discussion on variables. That was a lot to take in. hope you guys learned a lot and we will see you guys in the next one.