From the course: Unreal: Blueprint

Working with variables - Unreal Engine Tutorial

From the course: Unreal: Blueprint

Start my 1-month free trial

Working with variables

- [Instructor] Now we're gonna take a look at how we can create and work with variables in Unreal Blueprint. So I'm gonna go to my 05BP folder, open up this BP example 01. First got some simple text rendering elements in here, and what we wanna do is in the lower left-hand corner of the screen where it says variables we wanna click on this plus and you can see that creates a new variable. I can title it whatever I want, so I will title it VARIABLE_01. So there's a few different things we're gonna look at on this variable. If we go to the upper right corner you can see the name that I had typed in shows up there. We can choose a data type. I'll make this an integer. And there's many different options. The main one I'm gonna show you right now is this Expose to Cinematics checkbox. Can turn that on and then that will allow you to then animate that within a sequence or a matinee so then you could create an animation that would drive this depending on what you were building. The other important thing down here is you notice on the right side of our variable you see this little eyelid and you can see the tooltip is telling us whether it's public or not. If I click on this it opens up that eye, and then that allows that variable to be edited from outside of this blueprint, meaning we could have one blueprint set the variable of another blueprint because as we build more complex systems we can often have a lot of different blueprints and sometimes we wanna have the blueprints setting data on other blueprints. So I'm gonna show you a system later that uses this so you can build really modular stuff in a nice way. Okay, so that's how we create a variable. I could right-click on this, duplicate it. It'll make another variable of the same type. I could rename it. I could go up here and change it, say from integer to a Boolean so then we see the color update here. All right, I'm gonna delete out this VARIABLE_02. And so now that we have a variable in the system we need to be able to both read from it and write to it and that's really easy. I just drag it into our graph. And you see we get two options. We get a get and a set. A get is gonna get us the value of the variable with just one output pin and that we can feed into anything that's gonna read that. And then if I drag this again and it says set, there we go. Now I have a set option. Now the set gives us a few other pins because of course we need an event pin to drive this setting of the variable and we need the input pin that would be the actual value or setting. And then we have sort of utility pins on the right that will just keep flowing that event stream out and then we'll also just pass the value we sent into that right out again. So that's the way we set and get the values of the variables. Now let's go move on to start using this stuff.

Contents