Hello guys and welcome to the Blueprint
for Intermediate Users tutorial. This is the second video in my Blueprint
for Beginners series where I teach you how to use blueprints, the visual scripting
system inside of Unreal Engine 5, and in this video I will be explaining some
intermediate blueprint topics such as what are enumerations, Structures and arrays. These are data driven variables that
are essential to using blueprint inside of Unreal Engine I will also cover over
some of the other things that I skipped over in the previous video Things like
what are blueprint functions what they are used for and how to create your own
blueprint functions Finally, we will be using all of the things that we learned
in the first half of this video to create a simple inventory system That features
different items that our character can pick up And each individual item that
we create has its own unique stats and variables, and also the ability to use
the item with its own custom logic. So we will create things like a simple
health potion that the player can pick up and consume, and it will restore
some health to their health bar. We will create this little hatchet item. that the player can pick up and equip. And then we will finally create this
little book item that will display some text on the player's screen. Now this video will cover all of
these intermediate topics, and if you reach to the end of this video
and you end up enjoying this free tutorial, you can check out some
of my premium courses on smartpoly. teachable. com. If you are interested in making games
inside of Unreal Engine, luckily for you, I have a complete Multiplayer
survival game course where we create a complete multiplayer survival
game from scratch and we'll be adding more courses in the future. So chances are, if you're watching
this video in the future, you can check out my website, smartpoly. teachable. com to check and see if
there's any new courses. Now, this is the second video
in my blueprint beginner series. So if you haven't watched the first
video blueprint for beginners. I highly recommend that you go and
watch that video first, as it will explain the bare basics of blueprints. And in the future, I will be uploading
a follow up video to this one, titled Blueprint for Advanced Users, which
will be the third and final video in this series, and it will dive into
more advanced topics in blueprints. Things like blueprint
interfaces and so much more. So if you want to stay updated for
when that video is released, now is a good time to hit that subscribe
button and the notification bell icon. It's completely free and I'm
trying to hit over 100, 000 subscribers before the end of 2023. Now without any further ado,
let's get right into the video. Okay, so the first thing that
we're going to do is we're going to create the project. So for this video, we're going to be
selecting the third person character template, and we're also going to be
leaving this as blueprint selected. Now, I'm not going to include
starter content in this video, so I'm going to leave that unchecked. And for our project name, we
can go ahead and just rename this to Intermediate Blueprint. Okay. And then click create. So that will go ahead and
launch Unreal Engine 5. 3. So now that we are here in the
editor, let's go ahead and open up our third person blueprint. So in our previous video, we
were messing around inside of the third person blueprint. So to navigate to there, we just want
to go to our content, third person. Blueprints open up our third
person character blueprint class. I'm gonna go ahead and dock this
window up here at the top now I kind of want to talk about some of the other
variables that we didn't discuss in the previous video things like Enumerations
and structures as well as arrays. So the first thing that we're going to
cover are Enumerations so enumerators are essentially user defined So if
I create a new variable in here, I can name this to my test enum. And in the boolean type,
we can search for enum. And you can see there
are a ton of different... enumerators under the enum variable type. So these are all built into the engine. These are different type of enumerators. Now let's actually make our own
custom enumerator because you can actually create your own custom type. So in our content, let's make a new
folder, right click, create a new folder. We'll name this to underscore main. So that will just send the
folder to the very top left. I'll just keep everything organized. And in there, we're going to
right click, create a new folder. And name this to Enums. So in this folder, we're
going to open that up. And right click. And to create a blueprint enumeration. Instead of going over here. Under the basic asset. We're going to go down
to the advanced asset. So under the advanced asset we have. A category for blueprint. And you can see we have
the same blueprint class. That we have up here. But we also have a couple of
different things that we can add. We have things like a
blueprint function library. A blueprint interface. Macro library. And then down here we
have this enumeration. So we're actually select this
enumeration and now I'm going to name this to E underscore test enum. So now I can double click and
open this up and what this will show us is the enumerator window. So I can add. A enumerator by clicking this plus icon
right up here and it adds this display name and the description really you just
want to focus on the name so in our case we can name this to is walking question
mark and we can add another enumerator and we can rename this to is flying question
mark add another enumerator this will be our is swimming question mark and add
one last enumerator and this can be is sitting question mark so save that you
Now if we close out of this enumerator, we can go back into our third person
character, select the my test enum that we created, change the variable type
from boolean to E underscore test enum. So if we type in E test enum,
we can search for that E test enum that we created. I'm going to go ahead and select that. And then we have to compile the
blueprint to see the default value. So let's go ahead and
hit compile and save. And now we can see we have that
default value, my test enum. So we gave it those different
options, those four different options. And now you can see if we click on it,
it gives us sort of this dropdown menu. So really all that enum is, is a set. Of different options that
you can define, okay? User defined options. So I can select is flying, is swimming. Is walking or is sitting. And basically I can define
my own type of settings. This is super useful because rather
than having a bunch of Booleans to store, whether or not you're
walking, flying, or swimming, you can have an enum that will store. Say the state of the character or other
different variables that you might have, and you can just switch between all
of them by using an enumerator rather than multiple different variables. Now to actually get this on the graph,
let's go ahead and mess around with that. So I want to add a F key,
so I'm going to do a F key. And then we're going to get our
test enum on our graph, so we can drag this and get this on our graph. And then with this, you can actually
drag off here and do a switch on. And you're going to see, we
have the switch on e test enum. So if we select that, you're
going to notice that it gives us this execution pin. I'll hook this up for the pressed. So basically depending on whichever enum
that we have selected, the following execution pin will be executed. So for example, I currently have
our test enum set to is swimming. So this is swimming execution
pin is going to be fired off. So if I were to take this
and set this to is walking. This is walking execution
pin it will be fired off. So again, this is super useful because
rather than having a bunch of boolean variables to keep track of all of these
other different states, you can just have an enum that will switch depending on. The enum that we have set,
and you can have different logic hooked up to that enum. So for example, we
could do a print string. So we do a print string for our
is walking, and we can rename this to character is walking. Then we could just copy and paste
this by doing control C, control V. And for our is flying, we can
name this to character is flying. Copy and paste this again. We can hook that up for swimming. Rename this to character is swimming. And lastly, copy and
paste this one last time. Hook that up for the is sitting and
rename this to character is sitting. So compile and save this. So now if we select our test enum,
you can see it's set to is walking. So now let's go ahead
and actually hit play. So hit play here and press F. You can see our character is walking. Let's go ahead and select this
enum changes to is swimming. Compile save. So if it's set to is
swimming, it should print off. Character is swimming. The press F you can see character
swimming and we can set this to is sitting compile that hit play press
F you can see character is sitting. So basically depending on whatever
you set the enum value to, it will switch and execute the following
execution pin that you have hooked up. You can also set enumerators. So for example, I could take
my test enum and set it. So if I set it on the graph, I can
set it like so by hitting this drop down, setting it to is swimming. So just like you're setting any
other variable, you can just set the setting here on the graph. So those are enumerators explained. Now, in the other video, we didn't
really cover how to actually add a comment to our blueprint code. So comments are like these
little nodes that you can see here, these little gray nodes. So really quickly to
add a comment for our... Enumeration here, we can just drag
over this, if you select over all these nodes, if you press C on your keyboard,
so if you press the C key, that will add a comment, so you can rename this
comment to enums or enumerators, and then if you move this comment around,
you can see that the code inside of it will be contained, and you can move
this anywhere that you want on the graph, also you can rename your comment
text if you want to, either by double clicking here, Or selecting it here. You can also change the
color of the comment. If you want to change
it to a different color. Then also if you want to show
the name of your comment. And have it so you can
see it when you zoom out. You can hit this show bubble when zoomed
so we've covered enumerations now We're going to cover the other different
variable types such as structures So structures are another important data
driven variable type inside of Unreal Engine and if you're doing anything
advanced such as creating a game or Some sort of interactive experience where you
need data to be stored you will likely be using structures at some point So let's
go ahead and create Our first structure. So if we go to our third person map
here, go back to our main folder. I'm going to right click, create a
new folder, and call this Structures. So double click and open that up. I'm going to right click
and create a new structure. So under the Advanced Asset here,
under the Blueprint, at the very bottom we have this structure, okay? So let's go ahead and select that,
and then we're going to name this to S underscore test structure. So double click open that up. Similar to the enumerator that we saw
here, instead of adding enumerators, we can actually add variables. So basically a structure
is a group of variables. So what this means is I can add any
type of variable inside of here. I can set this to any type of
variable and give it a name. So for our test structure, I'm going to
change this first variable to a text. I'm gonna rename this to player name
and this next one will be a boolean we can rename the Name here to is dead
Question mark add another variable. This can be a float and rename this
to player health add another variable Changes from a float to integer. This can be our player level and add
one last variable and this could be our Even our enumerator that we created. So if I change this to our E
underscore test enum We can set this to our test enum, so I can
rename this to character state. So save that, this is our structure,
basically we can add any sort of variable that we want, and it
will be grouped in this structure. So if I close out of that and go back
to our third person character, we can now add that structure as a variable. So for example, if I go to the variables
tab and click the plus icon, I can rename this to character structure
and changes from our enum to our S underscore test S test structure. Okay. So you can see it's color coded
in this blue, dark blue color. So if I compile and save that in
the default value, you can see we have this character structure. So I hit this dropdown. You can see that we have all
those different variables that we. Defined in the structure when we created
it so we can change things in here. So this player name is a text so I
could say Smart poly So is dead is a boolean so I can hit the check box for
true or false Player health I could set this to like 100 hp player level. I could set this to something like 20
level 25 and then our character state we could set this to is flying is swimming
It's sitting to whatever we want it to. So basically that is a structure. The fact that you can create a structure
that has or stores multiple different variables can be very useful for things
like storing player data or really any type of data inside of Unreal Engine. So for structures to actually get it on
the graph, let's go ahead and cover that. So if I take my character structure, I
can drag this on the graph and get it. And you can see we have
this blue, uh, node here. So I'm going to actually take our F key. So if I click Alt to unhook that and
drag our F key down here, let's go ahead and cover how to actually get or obtain
those variables from our structure. So we drag off your structure. If you drop it on the graph, Down here
you're going to notice break s test structure so to get any of the variables
we have to break the structure So if you select that what you'll notice is
it creates or this node that you hit the drop down It will show all the different
variables that are stored inside of the structure So we have things like the
player name the is dead Boolean The player health float, the player level integer,
and then that test enum that we created. So now we can go ahead and actually
print out some of the data from this. So for example, we could even do
like a branch off of our is dead. So I could do a check, do a
branch off of our is dead. So if our player is dead, we could do a
print string, print off player is dead. Now if our player is not dead,
we could do a print string. And we can print out some basic
information about our character, like our name, so we can take our name and convert
that to a string and print that out. We can print out stuff like our health,
so I can copy the print string again and print off our player's health. And we can even print off things like
our level, print that off, add another print string, plug in our level. And you can even print
off the character state. So if I print, copy another print
string, I actually take this enum and drag it onto a string. It will add this enum to string node,
which will convert the enumeration into a string that we can actually print off. So now if I hit the F key on our keyboard,
it will print off our character structure, which, if it's not set to dead, it
will go ahead and print off all the information, like our character name. The health, the level, and the state. So compile, save, let's hit play. If I press F, you can see it is sitting. Level 25, 100 HP, and
our name is SmartPoly. So I could set this to IsDead to true. Then it should only
print the player is dead. So hit play, player is dead. So basically that is how you can
retrieve data from a structure. You have to break. The test structure and that will
retrieve all the info from the structure. Now. Another useful thing is let's say
I only wanted to get the name the is dead in the health variable. I can actually hide these other pins So
if you select this node in the details, we can do hide unconnected pins Now
we'll go ahead and hide those other two pins Okay, you'd also hit this little
drop down default category and we can enable or disable Whichever pins that
we want to use for our break structure. So just a nice little neat
bit of information to know. Now that is how we can
retrieve info from a structure. How do we actually set
a structure variable? So let's add a comment for this. This is press C on your keyboard. That will add a comment. This will be called break structure
equals retrieve info from variable. So how do we actually go
ahead and set a structure? So to set a structure, you can get your
character structure, drag it on the graph and do a set character structure,
but instead of breaking a structure, if you drag off of this character
structure, you can do a make structure. So we have the make,
and we have the break. So the break is to retrieve value,
the make is to set the values. So just like this other node over here, we
can select it and hit this drop down, and you can see we can set all the variables. inside of the structure. So for example, I could
Set our player name to Joe. I could set his player health
to 20, player level to 1. And I could set his state to swimming. So if we actually take this and move
this up here, so if I move our comment over, I could Unconnect our F key by
clicking the alt to break that, then hook up our set before our break. So now if I set the variable to
this new info, so we're going to change the default value to Joe,
player health 20, player level one. If I make that structure, then break
it, we should see the new info. When I press F, so hit compile and save. Okay, so we're getting a enum
to string has invalid value. Okay. So because I unhooked this enum to
string it's giving us this error. Actually, let's hook this back up So
character state hook that up player level hook that up hit compile and save and
now that error went away So now let's go ahead and play test this out by hitting
play press F You can see our name is Joe. Our health is 20. Our level is 1 and we're set to is
swimming So that is really how you can set a structure or set the values
inside of a structure by doing the make Structure now, there is one other way
to set variables inside of a structure. It is a little bit more Advanced but
basically what we can do is get our character structure and there's this
node called set members So you can do the set members and test structure and
this node looks very similar to these other nodes over here But instead of
making or breaking it you're setting the values inside of here So under the
default category if you have this selected you can set pins that you want to set
and that will go ahead and give You the struct out which we then want to go ahead
and do a set so set character structure plug that struct out Into that variable. So this is sort of like the make,
but instead of making or changing all the different variables inside of
here, we can select which variables that we want to actually modify. So for example, if I only wanted
to modify the player name, I could change this to Joe, and then I could
disconnect this, delete that, and plug this up here to our F key. So we're getting our character
structure, we're setting the member or the variable player name to Joe. We're setting that and now we're
going to break that and print it out. So now let's go ahead
and hit play, press F. You can see it's printing
off player is dead. So we need to go back to our
character structure and uncheck that. So uncheck the is dead variable there. So go back and hit play. So you can see our name is now set to Joe. Our HP is 100, our level is 25. All those other variables are still saved. Whereas the only variable
that we set was a Joe. So the set members allows you to
modify variables inside of a structure. The only variables that
you want to modify. So this is very different
than the make structure. Now those are the basics to
structures and enumerations. Now the last thing I
want to cover are arrays. So if you go over to the variables. We're going to create a new variable
and name this to array of player names. So we're going to change this
from a structure down to a string. Hit compile and save. And then if you hover over this
variable type, you can see this little icon over here to the right of it. If you hit this drop down, we
have a single type, which is currently what we have it to. You can see it's one. We can hit this drop down
and change it to an array. So now we have to hit compile. And now what you're going to see is we
have this default value array of player names, and we have zero array element. We also have this plus icon
and this trash or delete icon. So basically what an array is sort
of like a collection of variables. So in our case is a collection of strings. So I can click this plus icon and
you can see it adds one string. Or one array element. So in our case, we could
rename this to John. We could add another array element. You can see it as index zero and next one. I can rename this to Joe. And basically we can use this array of
player names to store a list of names. Okay. So you can think of this
as sort of as like a list. I named this John, Joe, Bob
could add another variable. This could be smart, Polly at another
variable, and this could be Ben. So compile, say that we have sort of
this array or this list of player names. So one thing to know about raise is
that they start at the number zero. So basically it starts. Index 0, 1, 2, 3, 4. Okay, so you see it's, there are
five array elements, but this is index zero, index one, index
two, index three, and index four. Okay. So you wanna always note that
arrays start at index zero. So now to actually get this array on our
graph, if we drag this onto our graph, we can get a array of player names. And you can see we have this. Square array icon, similar to what
we see over here on a variable type. Now to actually get our player
names, let's say we want to add some basic logic to print off all
of the player names to our screen. So the way that we could do that is off
of our array, we can do a for each loop. So under this utilities array, we have
these different nodes that we can use. And we have this for each loop node, okay? So if I select that, what this is
going to give us is this for each. So what the for each loop does, is for
each of the array elements, we can plug in some logic to the loop body, and it
will output each individual array element. For this execution, let's
actually hook up a key. So I'm going to type in the E
key, so the E key on our keyboard. So let's select that keyboard
event, hook that up for our pressed. And then for this loop body,
we can add a print string. So this loop body will get fired off
every single time for each array element. So for this array element, we
can plug this into the string. And that will go ahead and print
off, for each of the player names, it will print off every single name. It will print off John, Joe,
Bob, SmartPolly, and Ben. We also have this array index, which will
print off the index at where that name is. So for example, for John,
that will be index 0. For Joe, that will be index 1. Okay? And so on. And then once it's complete, it
will execute this completed node. So I could drag off here
and do a print string. And we can name this to those
are all the names in our array. So we'll just know that this loop
completed through printing all the names and then we printed off basically that
we completed printing off all the names. So now let's go ahead and test this out. So if we press E on the keyboard,
it should start printing off all of the names that we have in our array. So if I hit play, press E, you can
see that I printed off all the names. So we have John, Joe, Bob, Smart,
Polly, Ben, and you can see those are all the names in our array. So basically what this is doing
is it's looping for each of the names and it's calling our
print string for each of those. Continues to loop until the
array is complete and then it will call the completed string. So that is how you could print
off or loop through all of the variables inside of an array. You could also get
individual array elements. So for example, if I were to get my array
here on the graph, if you drag off here, you can do a get and you can see we have
array, get a copy and get a reference. So I'm going to go
ahead and do get a copy. And now what you're going to see
is we have this get node where basically we can specify an index
and that will return an output. So let's go ahead and take our E
key and unhook that by pressing alt. And then hook this up to a print string
and then hook that up for our pressed. So when we press the E key, that will get
from our player name array at index zero. Okay. So currently this is set to index zero. So what that should
print is the name, John. So if I hit compile and
hit play, I press E. You can see it prints off John because
John is the name at index zero. So if I set this to index one. I can hit compile and save and press play. I press E. You can see that prints off Joe
because Joe is the name at index one. So I could change this to index three. You can see index zero one, two, three,
number three here is set to smart poly. So if we get at index three,
it should print off smart poly. So I'd compile hit play, press E. You can see it prints off smart poly. So that is how you would
get a specific index. In the array by using the get node now
moving on you could even modify this logic to get a random name So for example, if
I wanted to get a random name in this array One way that we could do that is
we can modify what we have set up here by doing a random Integer in range. So if we jog of this we could do
a random integer Random integer in range and then we can specify a
range to Select a random integer. So for example our Array starts at index
zero and goes all the way up to four. So we could leave this as a minimum
of zero and a maximum of four, or we could also get the length of this array. So there's also another node. If you jog off this array called length. So if you get the array, you can
get the length of that array. Now we'll return the length of
this array, which in our case should be five array elements. Now, if you were to plug this
into this random integer, that will allow it to pick. A index outside of the array values. So, for example, this will print off 5,
so if I hook this up into our end string. If I compile and save and press
play, press E, you can see that the length of our array is 5. But if we want to get a random
integer from our array, we want to have a range from 0 to 4. So one way that we could do
that is we could do a subtract. So operator subtract. Just subtract our length by 1. And then hook that up
for our maximum value. So now it should be a range from 0 to 4. And what this will do is it will
get a random name in our array and print it off to our screen. So I press play and press E. You can see SmartPolly, Joe,
Bob, Bob again, Joe again, John. So you can see it just randomly picks
a name and prints it off to the screen. So that is how you could
do sort of a random integer within the range of an array. Now we've gone over how
to get array elements. Let's actually go over
how to set array elements. So there are a couple of
different ways that you can add array elements or set them. So down here below this, let's
actually add a comment for this. This can B, you know, just for each
loop, print off each player name. And then this is our print a
random name from our array. B. So for setting array elements, if we
go down here, we can actually get our. Array, our array of player names, and
we have a node called the add node. So if we drag up there and do
a add, we have this array add. Now what the add node does is
exactly what it sounds like. It will add another array element. So for example, I could name this to test. And then I could hook up
a key to print this off. So if I add the F key. So I believe we're using the
F key all the way up here. I'm gonna unhook that
and drag this down here. So when I press the F key, we'll
go ahead and add that to our array. And then we could also do a git so
I could get my array of player names and do a gi uh, array, get a copy
and we can get it at that index. 'cause you see it returns this index of
where it's being added in that array. So if we get. At that index from our array, we can
get that exact value that we added. So then we can do a print string and
hook that up like, so if I compile and save, if I press the F key, that will
go ahead and add test to our array. And then we can go ahead and print
that string from that array index. So I press F you can see it printed off
test because it added that array element. To our array we're getting it at that
array element and printing it off. So really those are the basics of arrays
Hopefully I didn't confuse you too much But you can essentially get from
arrays the values You can also add more values to arrays later on in the video. I'm going to cover over how to actually
set specific indexes in the arrays But basically arrays are very useful for
storing data because you can store a group of variables You can even change
this to a rate of booleans array of integers array of floats Really any other
type of variable you can even change this to an array of structures So for
example, I could add Another variable And this will be our player array. And I could change this from a
string variable to that S underscore test structure that we had. And you can see, we now have
an array of those structures. So hit compile save. We have this player array. So if I hit add array element,
you can see that it added this index zero and we can expand this. And now we have this player array
where I can add player name. Joe and set whether or not
is dead is true or false. We can set the player health,
the player level, the character state, and we have this index one. We can also change this to smart Polly,
change the is dead player health, the level and a character state. We can even add more, uh, array elements. Now if you wanted to actually delete
array elements, we can select this, hit this little Down arrow and click delete
And that will delete Array elements. Okay, if you were hit to this delete
that will remove all array elements That will just delete everything out
of the array So arrays are super useful for storing data because you can store
things like player info Stats or really any variable type Now let's go ahead and
move on to the next part of this video where I want to talk about functions. So in our previous video, the blueprint
for beginners, I didn't really talk about functions and what they are. So I'm going to go ahead and take
a moment to cover over what are functions and how to use them. So first of all, a function, if
you look in your blueprint tab down here, we have this functions section. So just like variables, we can add new
functions by clicking this plus icon. And first of all, let's
go ahead and actually. Talk about what are functions. So if you actually look really closely
here on the graph a function It's sort of like this node right here. So this is a function Because you
can see that it has this F logo right there with that little F icon
This is a print string function. There are more other
different types of functions. So for example This
random integer in range. This is also a function Because
you can see that little F logo. So print string and random integer
and range, these are all functions. So even the character input
up here are functions. So for example, we have this jump. This is also a function. So functions are sort of like
these different nodes that can contain logic inside of them. So for example, we can actually
create our very first function. So under the functions, I
can click this plus icon. And what that will do is it will
create a new function, so I'm going to leave that as new function. So if you click on the graph, that will
go ahead and finalize the name there. So you can see it says new function. We are in this function graph,
so I scroll in and out, it's the same as the normal event graph. I can change tabs between the
event graph and our new function. So the function sort of gives us its
own blueprint graph that we can put our own blueprint nodes and logic inside of. And now we have that function
over here on the left. So for example, for our new function in
here, it gives us this execution pin. So we could drag off here and do a
print string, print string, and we can print off some info to our screen. So we print off a little text
saying, this is my first function. So if we hit compile and save, we can
go back to our event graph and then off of our F key, what we can do is
delete all that and call this function. So I drag off this, I
can call it on the graph. I could also call our function
by right clicking and searching for new function and you can see
call function and new function. So this is our new function. So if I plug this into our is
pressed, So I press the F key, it will call this new function, and if you
double click it, it will open it up. So you can either navigate by double
clicking the function over here, that will pull it up, and you can change to the tab
over here, or you can double click the node and that will open up the function. So basically when we call this
function, it should print off, this is my first function. So when I press the F key, it
will call that function and print, this is my first function. So if we hit compile and hit play, press
F, you can see this is my first function. So really a function allows you to store
blueprint logic inside of it And this can actually be very useful for if you
are going to be reusing a node multiple times So for example, if I have a bunch
of logic that I'm going to be reusing multiple different times I can put that
logic inside of a function and then I can just copy and use the function
wherever I need on the graph rather than copying Say a group of nodes over
and over, and this will help a lot with organization and also with optimization. Because rather than having a bunch of
nodes on your graph, you can just have a function that calls all those nodes. That way you don't have to have
all those nodes copy and pasted in multiple different locations. So functions also have different
types of settings, and they can also input values and output values. So for example, If I were to double
click and open our function, I can select this purple, uh, new function node. And in the details here,
we have some settings. So what we want to focus on
first is the inputs and outputs. So first let's go ahead and add a input. So I click this plus icon
on the input that will allow us to add a input variable. So we can pass information from
outside of the function to the inside. So for example, I could
change this to a string. We can name this to player name, compile
and save, and then we can hook this string up to our print string, and now if we go
to the event graph you can see that we now have this input player name, where we can
either type in here smart poly or the name of your player, or we can even hook it up. To a string variable. Okay, so we can add inputs to the function
Which then passes that variable inside of here, which we can then use to do whatever
we need to do inside of the function so if I pass the player name smart poly into
this function And we'll go ahead and take that name and print it to the screen. So if I hit play and press F, you
can see that it prints smart poly. So that is how you would
add things like inputs. You could add many different types of
inputs, but you can also add outputs. So for example, I could delete this input. And once you delete inputs like this,
you can see that gives us this error. So if you press alt and click on that,
It will remove that pin and you see it's no longer giving us that error
so I can hit compile and save so I can add more different types of inputs so I
could come in here select that and add another input I could change this to
a float and rename this to damage and I could also add another variable and
rename this to health and then we could add a output value by adding an output
you And what you're going to see is it adds this output variable, but also this
return node with that output variable. So I can rename this variable to out
health or health after our damage. And I could take this return value and
plug this into our execution pin flow. So basically we're going to get our
health and do a subtract, subtract that by the amount of damage. And then we can plug this into our
out health, we can even delete this print string and plug it in like that. So basically this function is taking a
health variable, subtracting that by the amount of damage that we take, and then
returning the out health as a output. So we head to the event graph, you can see
that we now have those inputs and outputs. So for example, I could give
our health a value of 100 HP. I'd give our damage, say, 30 damage. And then for our out health, we
could do a print string and hook up our out health to the string. And that should print out our health
minus the damage and print it out. Okay. So if I hit compile and save
and hit play, I press F on my keyboard, you can see that it's. Our health is 70. Because our health is 100
minus 30, which equals 70. So it's running through that function. We have things like inputs. And we also have things like outputs. So really those are the
basics of functions. The fact that you can store
blueprint logic inside of functions. and call them on the graph will be very
useful, especially for reusing bits of logic that you might want to reuse in a
couple of different places on your graph. Okay. So now we're going to actually pivot
the tutorial so that we can go ahead and actually work on our inventory system. So basically we're going to
create three different items that we can actually pick up. And when I have a simple inventory
hotbar on our screen, and we're going to use all of the things that we just
learned, things like enumerations, structures, arrays, as well as functions
to program the entire thing together. So let's go ahead and
start working on that. So if you head back over to your content
drawer, I'm actually going to dock this in layout and then go to our main folder. And the first thing that we're
going to need to create is a enumeration for our item types. So open up your enums folder
and we're going to right click and create a new blueprint. Enumeration. So this will be called eCore item type. So our item type enum. So double click, open that up
and dock this up here at the top. So for the enumerator, we're
gonna add three uh, different enumerators in here, and the first
one will be called consumable and the second one will be equable. Then the last one will be called readable. So basically these are the three
different item types, and depending on the item type that we set, it
will do different logic, okay? So consumables that will consume like
a potion that will restore health, equipables that will equip like an item,
like a hatchet to our hand, and then a readable will just show some text on
our screen that the player can read. So we're just using that enum so we can
switch on those different item types. Okay, so let's go back to our content
browser and back to our main folder. Now we need to create a structure
that will hold all of the item info. So in our structures, we're going to
right click, create a new blueprint. Under the blueprint section, we're going
to go down to structure, select that. This will be called S
underscore item structure. So just double click, open that up. And we're going to add a couple
of different variables in here. The first one being that
enumeration that we just created. So this first one, let's change
this to that E underscore item type. So we have E item type. And we're going to
rename this to item type. Okay. So save that. Create a new variable. This will be set to a static mesh. So we want to search for static mesh. And then if you hover over
Static Mesh, you're going to have these different options. What we want is a Object Reference, okay? So if you select Static Mesh, you
want it to be Object Reference, or this blue color right here. So this, if we rename the name on
here, this will be called just Mesh. The Mesh of the item. Add a new variable. We're going to change
this one to an Integer. And then rename this to Damage, okay? So this will be how much damage this item. Can do and then we're
gonna add another variable. This one will be a text and we can rename
this to item name Okay, so this would be the name of the item Add another
variable when it changes from a text to a texture 2d So if you look down here,
we have texture 2d and again, we want to set this to an object reference. So select object reference So rename that
one to item icon So that will be like the user interface icon of this item and then
add another variable and this would be a text And we'll rename this to item text. Okay. So if we have any, you know, details or
description, or even if this is an item readable type like a note, we could put
that inside of this item text variable. Okay. So that is our item structure. We will be adding one last
variable inside of here, but we'll come back to that later. So this is now complete. So if we close out of that, we now have. The basic data types for
our inventory system. So we created that enumeration,
the item types, and then we created our structure, the item structure. So now what we need to do is
we need to create the actual blueprints for our blueprint items. So I'm going to right click in our
main folder, create a new folder, and we're going to name this Blueprints. And double click them and open that up. And we're going to add a
blueprint class inside of here. So we just want to right
click and add a new... Create basic asset blueprint
class and it's going to have a select a parent class. So our case, we're going
to pick the actor class. So select that and rename this
to BP underscore item master. So it is our master item. Now double click and open this up
and dock this up here at the top. And inside of this blueprint,
we're going to add that item structure that we created. So in the variables, we want
to click on the plus icon and just rename this to item info. Then we want to change it from a boolean
to our S underscore item structure. So compile and save. And now if you have that item info
selected in the details, if we expand the default value, we have all of those. variables that we can change. So we can change things like the
item type, if it's a consumable, equipable, or readable. We can set stuff like the
static mesh, or the item mesh. We can set the damage of the item. The item name, the item icon,
and then also the item text. Now we're actually not going to be setting
this variable inside of the master class. We're going to be setting it in
the children class, and we're going to go over that here in a second. But the other thing that we want to add
inside of here is we want to add a little collision sphere so that we can overlap
with it and actually pick up the item. And then we're going to add a static
mesh component so that we can actually see the mesh that we want to pick up. So in our components tab, the
first thing that we want to add is our sphere collision. So I have collisions, sphere collision. And then also you want to
select the default scene root. And then on top of that
add our static mesh. So they should be side by side like this. Then I'm going to take this sphere
collision and scale this up. So I believe I scaled this up to about 6. 5. And then for the static mesh. We can just set this to a simple
mesh, so select the static mesh component, and in the static mesh, in
the details panel, we can set this to a cube, or actually set this to this
cube 1, okay, so this little mesh. Then we can actually take this
and scale this down, so I'm going to scale that down to 75. So compile and save that, and now
we can actually drag this item master blueprint into our level. So we can drag that in there. So this will be our simple item
pickup that we can overlap with the sphere and we can actually pick it up. Now we don't want to set any of the
variables inside of the master class. Like I said, we want to make a
child class where we can actually set all of the info inside of. So to create the children blueprint or the
children classes Basically, we don't want to duplicate this BP item master because
let's say we wanted to add multiple different types of items If we actually
go ahead and duplicate this blueprint, that means that we have to Set up the
interaction logic per each individual item and let's say we have you know
hundreds of items Maybe even thousands of items in our game It's just not going
to scale well with performance because of having all that logic Duplicated
rather than having a single class that has a logic and then all the other
classes sort of use that single logic Okay So this is where having a master
class and a child class comes in handy. So first to create the actual child class,
if you right click over the blueprint, so our blueprint item master at the very
top, we have blueprint class actions, and we can create this child blueprint class. So if I click on that, Now it's going to
add this BP item master underscore child. And I can go ahead and actually rename
this to BP underscore item book. And then we can go ahead and
double click and open this up. So what you're going to notice inside
of here is it pretty much looks the exact same as our item master. So you can see it has the cube in here, it
has the sphere, but inside of our BP item book, the main thing that you need to note
is that it inherits the same variables and the same components as in our item master. So what that means is in our item book,
you'd see we have the cube and the sphere. We also have Or item variable. So you're not going to see it under
the variables tab, the item info. But if you head over to the class
defaults, under the details, if you click class defaults, we have this default tab. And you can see we have that item info. So if you expand that, you can now see
we have that item info structure variable that we had inside of our item master. So whenever you create variables
inside of the master blueprint, In the child blueprint, the variables will
show underneath the class defaults. They won't show anywhere inside of here. Also another thing with the children class
is you're going to notice the parent. So up in the top right you can see
parent class is our BPItemMaster. Which is master class. Now the reason why we want to use a master
and a child class, is because I can change all of the values of this ItemBook class. So I can change the mesh. Select this static mesh and
change it to, say, this cone. So compile, save that. And then if I browse and drag
this into our level, you can see we have this different mesh. Now if I were to change any of the
settings inside of our item master, so for example, if I were to add the
pickup logic and all that stuff inside of here, it's going to update for our... Other children classes like our item
book and our other types of items, so it's going to make it a lot easier
It's going to save us time having to program the interaction and also it's
the preferred method for designing complex blueprint systems inside of
Unreal Engine now this children and Masterclass is also called inheritance
and again what that means is any of the changes inside of the master class Will
be inherited by the children classes. So if I were to reset this cone back to
the cube and the item book, if I go into our item master, I could select the cube. And in here, if I change it to a
different mesh, let's say this editor's sphere, if I compile and say that and
I go back into our item book, or in the children class, you can see that it's
inherited that change from our master. So basically the children class inherits. Any changes or any updates and
really all of its properties from the parent class or the item master. Okay, so I'm going to set that back Now
this is also very true in Unreal Engine itself the way that the engine is designed
so what I mean by that is if you go into your content folder and right click inside
of here and Under the Create Basic Asset, if we select Blueprint Class, you're going
to notice this says Pick Parent Class. So, in Unreal Engine, they already
have a type of parent and child class set up with their Blueprint system. So, in Unreal Engine, the first thing
that you have is called an object. So, an object is basically something
that can exist in Unreal Engine. Then from the object, you have an actor. So, an actor is an object. That can be placed or
spawned in the world. Then from the actor you
have sort of this pawn. So the pawn sort of inherits
the actor's ability to be placed or spawned in the world. But what the pawn class has
is additional logic that can receive input from a controller. So it can be possessed and receive input. Now the character is also a type of
pawn, so it inherits the pawn's ability to be possessed and move around. But it also has some additional logic. For its ability to walk around. So you can sort of see the type of
inheritance and the parent and children classes inside of unreal engine, just
from this blueprint creation screen. Now that is basically
inheritance one on one. Let me know if you need any
clarification in the comments down below. But now let's go ahead and
actually set up all of our children blueprints or our item types. Things like our item book. So for that we're going to
need to import the assets. So I want to head over to the
description of this video and download the project files for this video. And in the main folder we're
going to right click and create a new folder called resources. And so once you download the project
files, you just want to right click the zip file and click extract all. And once you've extracted the
files, we have this project files folder, we have some 3D models,
and we also have some icons. So first things first, we created
that content main resources folder. So let's right click, create a new
folder in here, call this item icons. Then double click, open that up and
in our project files, we have icons. So open that up and select all of
the item icons and drag and drop them into our item icons folder. Okay. So it's imported that. So that's all good to go. So head back out of the resources
file, then in here, we're going to right click and create a new folder
and call this item and meshes in there. We're going to right click
and create a new folder. This will be our item book. And then we're going to
create another folder. This will be our item hatchet. And then one last folder
for our item potion. So first open up our item book. Then go to our project
files, 3D models, book. And select all this and drag and
drop it into our Item book folder. It's going to ask us to import the FBX. We're just going to click import all. I'm going to leave all the settings as is. So click import all. It's going to say no
smoothing group was found. That's okay. We can just click this X and that's fine. Then let's go back to our item meshes. Let's go to the next
item, our item hatchet. Let's go to our 3D models, hatchet. Select all the files in here and drag
and drop it in our item hatchet folder. Again, it will pop up with
the FBX import options. We'll just click import all
and that should be all good. Then lastly, let's go back to our item
meshes and open up our item potion and go to our 3d models potion, select
the FBX and the texture, drag and drop it in the folder, click import all. It's going to say no smoothing group. Also, uh, texture name clash. That's okay. We can just close out of that. So now we can go ahead and
set up all the materials. So first let's go ahead
and set up our item potion. So we have this potion material. So we double click open that up. We just need to drag in the texture. So we go back in our third person map. We have this texture. We can just drag and drop this
into our material on the graph. Hook up the RGB to the base color,
and then we can delete this param. So save that, close out of there, and
then we should have our potion item. Then let's go back to our item
meshes, let's go to item hatchet. We have this material for our
hatchet, so double click open that up. And then, let's select our texture files. So all three of these, shift
select those, drag that into our material, onto the graph. Thanks for watching! And we can delete this parameter
and we should have these three different textures. So the first one, we have
this sort of wooden color. So take the RGB, plug
that into the base color. Then this next one will be our metallic. So take the RGB and plug
this into the metallic. And then this last one
will be for our normal map. So take the RGB and plug
this into the normal map. So then we can go ahead and hit save. And close out of that. And that should be good for our hatchet. Then lastly go to our
item meshes, item book. And double click and open up
the material and let's shift select all the textures here. So we have all four of these, drag
and drop them into our material graph. Let's delete the parameter here. So this red texture is our base color. So take the RGB, plug
that into the base color. And this next one is the metallic. So take this one and plug
this one into the metallic. Okay. Then we have the normal map. So take the blue texture and
plug the RGB into the normal. And this last one, we're going
to take the RGB and plug this into the ambient occlusion. So save that, and close out of there, and
now all of our items should be set up. So do a file, save all, and now
we have our item book, our item hatchet, and our item potion. So now let's go ahead and set
up the actual item blueprints. So if we go back to our main blueprints. We can open up our item, our BP item book,
so let's select the static mesh and in the details we can change this to our book,
so we have our book static mesh, and I'm actually going to scale this down, so
it's a little bit too big, so I'm going to select the mesh and set this to 3, 3
by 3, compile and save, and if we look at our level that should be good scale. And then also we want
to set up the item info. So if we head over to the class defaults
under the default Over here if we expand this we have that item info variable or
the structure and here we can actually set the variables Relating to our BP
item book So the first thing is our item type enumeration So we can hit
this drop down and we can choose what type of item that this is in our case
This is a readable So, it's a readable because it can be picked up and the
player can read it and it'll have some sort of note or some sort of text. Then we want to set the mesh,
so this will be our book. Our static mesh book, because
that is the static mesh. The damage, this won't have any damage,
so we'll just leave that as zero. The item name, we're going
to rename this to Old Book. Then we have item icons. So I'm going to click this drop down
and change this to our T underscore book So you should have a texture book. So this is the item icons that we
imported from the project files So that will be the item icon for our book. And lastly, we have some text. So for this, this will actually be sort
of like the text or note that when the player picks up this book, they can read
it and see what's written inside of it. So in here, I'm going to
write, Testing 1, 2, 3, 4, 5. This is some text inside of this book. So just some simple text. So compile and save and now
we set our variables or item info inside of our item book. So now let's go back to our content
browser and we want to create two more child classes of our item master. So we can right click this and
create another child blueprint class. And this one will be called BP
underscore item health potion. So double click, open that up and in
here when I select this static mesh and changes from the cube to our potion. So we should have this static mesh potion. So select that. We'll have that little
tiny potion right there. I'm going to select the mesh and actually
scale this up to one by one by one. Like that. And then let's go ahead
and in the class defaults. Under the item info. Let's go ahead and actually set up the
item info inside of here So this is actually going to be consumable type
So when the player consumes this health potion, it will restore some health for
the mesh We want to set this to our SM underscore potion or a potion static
mesh for the damage Instead of this actually doing damage We're going to
use this variable to restore health. Okay, so if this is a potion or a health
potion Instead of applying damage. We're going to restore health. So for the damage I can use a Variable
of say 30 so we can set that to 30 and that will be how much health it will
restore So the variables inside of here are very flexible because you can
use them any way that you want In my case, I'm using the damage variable to
restore health rather than item damage. Then we have item name, so I'm going
to rename this to health potion. Then we have item icon, so hit
the drop down and search for our texture, t underscore potion. So this is our potion item icon. Then lastly we have some item text, and
we're actually not going to be using that. So that should be all set and
then let's go back over here and let's create one last child class. So right click the item master and
again create a child blueprint class. And then this last item will be
called BP underscore item hatchet. Okay, so double click open that up. And in here we're going
to set the static mesh. So first select the static mesh
and change this to our hatchet. So we should have this
hatchet static mesh. So it's very small, so
we'll need to scale this up. So select the static
mesh and set the scale. We can actually hit this little lock icon. And if we just set the scale on one of
the axes, it will apply to all of them. So set this to 3. 5. And that should scale that all the way up. Okay, so that should be good. Compile, save that, also in the class
defaults, we need to go to the item info and change the settings in here. So in our case we want to change
this from item type consumable to an equippable because we can
equip this hatchet to our hand. Then for the mesh we want to
search for that hatchet mesh, so we have the hatchet static mesh. The damage we can set this to something
like 120, so we can do 120 damage. We have the item name, we can
just name this to Hatchet. We have the item icon, we can search
for that T underscore Hatchet. We have that item icon. And the item text, we'll
just leave that blank. So compile, save, and now we should
have all three of our items set up. So if we head back to our content
browser, we have the item book, item hatchet, and the item... Health potion, so I'm actually
going to delete this item master. Oh, that's in our level and Then we can
drag all three of these items out here. Okay, so we have our hatchet We have
our potion and we have our book Okay. So right now if I were to hit play and run
up to these items, they don't really do anything So we need to go ahead and set
up the interaction Logic so that when I run up to this item and I press e We're
going to go ahead and actually pick it up. So to do that, we want to
go into our BP item master. So we go into our master item. We're going to add the interaction
logic inside of this blueprint class. That way it will apply for
all of the children classes. Okay. That way we don't have to individually
set it up for each individual child class. Okay. If we just set it up in the master,
it will inherit all of that logic. So in the event graph. We can actually delete
these event be in place. We don't need any of those We're going
to select this sphere So this is a sphere collision and in the event graph
if we scroll down in the details We're going to add a event to begin overlap. So click the plus icon there So we
have on component be an overlap for a sphere want to select the sphere
again and Scroll down and we should have on component and overlap so make
sure you have the on begin overlap and And the on end overlap for our sphere. So we're going to do a check,
check and see if the actor that is overlapping with this is our character. So again this is our cast
to third person character. And if it is our character then
we can go ahead and enable input. If it is not our character then
we can go ahead and disable input. So we're going to right click
and get player controller. And do a enable input. And actually want to take the target and
plug this in for the player controller. And then we want to go ahead
and do the same thing down here. Except we want to disable the
input so when they leave the sphere we want to disable input. So off the other actor we
want to cast two third. Person, character, then off our player
controller, we want to do a disable input. I believe we actually want to
hook this up to player controller. So hook that up like so. So when we overlap, we enable input. When we leave the
sphere, we disable input. Then we just need to add a key
that we can press so that when we press it, it will pick up the item. So up here at the top, we're going
to right click and add a key. So scroll down. We should have our E. Keyboard event. So when we press it, we want
to, off of our other actor, cast to third person character. And then we actually want to add a
pickup event inside of our character. So that we can call that event
and actually pick up the item. So that will sort of work as adding it,
or adding the item to our inventory. So that our character can, you know,
pick it up and equip it or consume the item, whichever logic that we set up. So we want to go to our
third person character. And in here, we're actually
using the E key already. So I'm going to go ahead and just
delete this, delete that E key. And down here on our third person
character in our event graph, I'm going to right click and add a new event. So add custom. ADD custom event and I'm going to
rename this event to pick up item event. Then we can go ahead and add a input. So this is going to have one input. So in the details, add a new
input, change this from a Boolean to the SS item structure. Okay, so we're gonna change it from
a Boolean to our S item structure. A variable type, then for the
name, I'm gonna rename this from new parameter to item info. So compile, save that, that
should be good for now. So now we can call this pick up event. So we head back over to our item
master, because we're casting to our character, we can off of this, uh,
blue pin, we can call that event. So if we drop that, we can call that pick. So pick up item event. So select that. And then for our item info, all we
have to do is plug in our item info variable so that we can pass that
variable to our pick up event and that will go ahead and pass that info
into our player character blueprint. So in our item master let's drag into the
graph our item info get that in the graph then we can plug that into the item info. Okay? Then the last thing that we want to
do is we want to destroy this actor. Or delete this item from the level
because our character is picking it up. So right after this, we're
going to do a Destroy actor. Okay? And then we'll go ahead and
delete this from the level. So now if I go ahead and test this
out, so if I hit compile and save, hit play, I should be able to
run up to the items and press E. So when I overlap, I press E and
pick it up and you can see that it deletes it from the game. And right now it's not actually doing
anything, it's just deleting the actor. It's not actually adding it
to our player's inventory. So we need to actually create
the player inventory array that will store all of the items. So if we head over to our BP third person
character, we're going to create a new variable inside of our variables tab. So we want to click the plus icon
and rename this to InventoryArray. And we want to change this from a boolean
to our s underscore item structure. So the item structure, it's the same
variable that we have for this input here. And instead of having it as a
single variable, we want to change this, hit the dropdown and change
this from single to an array. Okay. So we have an array of structures. So if we hit compile and save,
we can now add our item info. To our players inventory array. So we're going to get our
inventory array on the graph. And then we're going to drag and
drop this on the graph and do a add. So we have under the
utilities array we have add. So we select that. We can now hook up the execution. And then for item info we just plug
that into the blue pin right there. And now it's going to add that item
that we pick up to our inventory array. Okay. Now if we were to actually test this out. And hit play. We're not going to see
anything happening visually. It's technically added to the array, but
we don't really see anything happening. Now to actually see something happen,
what we can do to visualize this, is if we want to actually see those
items being added to this array, we can right click this inventory array. And if you right click it
right on the pin, we can do... Watch this value and what that will do
is it will allow us to see the actual values being added to the ray so we
want to hit this play icon up here and Then now that we're simulating this
under this no debug object selected If you hit the drop down you can see
that we have this BP third person character So we want to select that. So now you can see that we are
watching the array of S structures, inventory array, of this BP third
person character that spawned in. So if I move this side by side
here, if I run it to the book and press E, you can see that we
actually added an item to our array. So if I hover over this inventory
array, You can see that we have this inventory array number equals one. So we have one item in our array. So if you hit this little drop
down, you can see the actual item variable inside of that array. So we have index zero. So if I expand this, you can see that
we added that book that we picked up. So it's a readable. We have the mesh, that book, static mesh. The item name, old book. The icon and all the text. So it's adding that item to our array. So we go back in here, and if I
pick up the potion now, you can see that it also fired off there. So if I hover over this, you can
see our array is now equal to 2. So we have 2 items in our array. So if I expand this, you can see I have
item, or index 0, which is that book. Then I have index 1, which is
that consumable, or the potion. So if I expand that, you can
see it's a static mesh potion. The damage, the... Item name, health potion,
the icon, all that stuff. So lastly I could run up to
the hatchet, pick that up. And then again, we can hover
over our inventory array. It says number equals 3. So we know that we have
3 entries in this array. So if I expand that, we
should have index 0, 1, and 2. So this last one is that hatchet item. So we have the hatchet static mesh. We have the name of the item, have
the hatchet, and then the item icon. So basically, if you watch the value,
and if you set your debug object selected, you can essentially see
the values of the array at runtime. And this is super useful for not only
seeing the contents of arrays, but for also debugging your blueprint, okay? Now if I press escape out of
here, we can right click this and do stop watching this value. And then of course we can, uh, set
this back to no debug object selected. But basically we know that the
item is being picked up and it's being added to our inventory array. So now that we know that this is
working and functional, we want to go ahead and add a user interface or
a widget to represent our player's hotbar so that when we pick up an item,
it will show on the player's screen. So let's go to our content drawer. I'm going to dock this back in our layout. And I'm going to go back to the main
folder and right click, create a new folder, and this will be called Widget. So double click and open that up. And in here I'm going to right click
and create a new user interface of the type Widget Blueprint. And we're going to select User Widget. So I'm just going to name this
to W underscore Main Widget. Or Main HUD. And double click and open that up. So inside of here, this is
basically the widget editor again. I'm not gonna go too in depth about
widgets in this video I will be making a separate beginner tutorial covering over
widgets more in depth, but we're gonna keep this very simple So first things
first, we want to add a canvas panel. So we want to search up in this palette
for canvas Panel, so I want to take that and drag this on to our main widget
That will basically give us a canvas to start working on So, we want to
add a simple hotbar down here at the bottom that will consist of some item
icons or some images that we can set as item icons when we pick up items. Okay? So, it's sort of like any sort of
hotbar that you see in an RPG game. So, I'm going to go ahead and
first add a horizontal box. So, we have panel, horizontal box. Drag that here on the canvas. We can take this and scale this up. I'm going to sort of center this in
the middle like that, and then in there, I'm going to add a border. So search for border. We have this border. Drag that into the horizontal box. I'm going to select the
border and the details. I'll set that to fill and for the padding
here, I'm going to set this value to five. Okay. Then for the border, I'm going to
change the actual color of this. So you want to change under the
appearance, the brush color. You don't you don't want to change the
color and content and opacity you want to change this brush color Because
this will actually affect the contents inside of this border rather than the
actual color of the border so for the brush color you want to change this to
a Black color and then under the value under the advanced here So for our alpha,
I'm going to change the value to 0. 5 now. We'll add sort of this transparent value. So hit OK Pile and save
and then onto that border. I want to add a image. So search for image, have image and
drag and drop it onto the border. Then select that image. And I'm going to give this a padding. So over in the details, I'm going to
select the padding here and change this to 10 and then for the color
and opacity, I'm going to change this to sort of this grayish tint. So compile and save that. And then I'm just going
to copy this border. So select the border, copy
and paste it two more times. So you should have a
total of three of these. So select the horizontal box, let's
actually scale this up a little bit. So something like this. This will be our simple
hotbar of three items. Then I'm going to select the
horizontal box right here. And for our anchors, if
we go over to our anchors. We want to anchor this
at the bottom center. Okay, so select the bottom center anchor. So it should anchor it
down here at the bottom. Okay, so now we can compile and save this. And now we just need to add
this to our player screen. So in our third person character,
I'm going to right click and add custom event on our graph. And I'm just going to call
this to create our main HUD. And then off of this execution,
we can do a create widget. So select that, and for our widget,
or for the class, we want to search for our w underscore main widget. And for our owning player, we can drag
off here and do a git player controller. So git player controller. Then we just want to add
this to our viewport. Off the return value, we can do a
add to viewport, add to viewport. And then lastly, we want to save
this, uh, main widget reference. So off this return value, we can
promote that to a variable and let's go ahead and rename this
variable to WidgetReference, okay? So we'll save a little
reference to our main widget. So compile and save, now we just need
to call this CreateOurMainHudEvent off of our EventBeginPlay. So if you scroll all the way over here
to the top, under our AddInputMapping, go ahead and move this up. Off of our event begin play,
we're gonna do a sequence. So we're gonna do a sequence and that
will give us some extra execution nodes. So for uh, then zero, we're gonna
just do our add input mapping. Then for our then one, we're
gonna drag off here and call our create our main HUD event. So off our event be in play,
we'll add the input mapping, and then we'll create our main hud. All the way down here, which
will create our main widget and add it to our viewport. So compile and save that, and if we
hit play, we can now see our little hotbar down at the bottom of our screen. So now what we want to do is when
we actually pick up an item, we want to show the item icon on our hotbar. So whenever we pick up items, we want to
show it being added to our item hotbar. So the way that we're going
to go about doing that is... First things first, we need to go to
our main widget, and we need to, in our graph, add an event for changing
the image to set it to our item icon. So first things first, we're actually
going to rename these images. So I'm going to select this
first image right here. And in the details, we can
rename this to Image 0. And then this next one right here,
select that, and this will be Image 1. And then this last one
over here will be image 2. So I'm just naming this
to image 0, 1, and 2. Because it will be the same,
uh, index as our array. So, for example, the
array starts at index 0. So this will be the first item. Or index 0. And the second item, or index 1. And the third item, or index 2. So now let's head over to our graph. And this will take us to our
event graph inside of our widget. We have some of these events
already in here, but I'm going to select and delete those. We don't need any of those. So I hit compile and save. And we want to add an event to set those
images or to update those item icons. So I'm going to right click
and add a custom event. Add custom. And this will be called update image. So we need to add some
inputs inside of here. So that we can know which
image we want to set. So select that custom event and in
the details we should have inputs. So we can add a input. The first one will be a integer. And we'll rename this to item index. So we want to know which item. index inside of our array, are
we updating for our widget? So for our item index, we want
to do a switch on integer. And what the switch on integer
does, is we can add these pins. So we can add 3 pins total, and we'll
add a value, so we have value 0, 1, or 2. So it's sort of like a switch on
enumeration, but in this case it's switching on the different integer values. So we also want to add another variable
or input for our update image event. So select that and add another variable. This will be of the type Texture2D. So we have Texture2D. We want to select the object reference and
then we want to rename this to item icon. So we want to pass through the item
icon so that we can set the image icon. So now we just want to get
these variables or these images. These images are the images on our hotbar. So when I get image zero and get that
on the graph and then off of there we can do a set brush from texture. So we have set brush from texture so we
hook this up for Switch on into zero. This will set image zero and for
the texture We just plug in the item icon for the new texture. So basically we're setting the image
that new item icon Add to the index. So we just want to do this
for all the other images. So we want to get image one And also do
a set brush from texture And then we're gonna plug that for Index one, and for
the texture we can plug in the item icon. We can also get image two, get that
on the graph and do a set brush from texture, hook that up for index two and
for the texture hook up the item icon. So compile and save. And now we should be able to
call this update image when we add an item to our inventory. So if we head back over to our
third person character We want to go to our pickup event. So this is where we pick up the item
So now to actually call that update image event What we want to do is
we want to get our widget reference. So we saved a reference to our main
widget So we can drag off here and get it. I'm actually going to select this
and move this down But for our widget reference we can call that
update image So update image event. So we have the item index, and then
we also need to get the item icon. So the way that we can get that
is off of our inventory array. We can do a git. So we have array git, so we
can get a copy of that array. And the index that we want to use
is wherever we add this new item at. So it returns the index
of the newly added item. So we can take that and
plug that into our git. And then off of the git, that
returns the S item structure. So if you drag off of here, we
can do a break, S item structure. And then if we expand this,
we now have the item icon. So for our update image, we
want to hook up the execution. For the item index, we can hook
up the item index, like so. And then for the item icon, Off of this
break as structure, we can plug in the item icon to the item icon like so. So now what it's doing is it's adding
the item to our inventory array. Then at that index we're getting that,
we're getting the item icon from it, and we're updating the image at that index. So now if we hit compile and
save, let's go back to our third person map and hit play. If we run up to this book, if we press
E, you can see that we picked up the book, it's added to our array, and
you can see on our hotbar we set that image at index 0 to that book icon. So I go up to this potion, I press E,
you can see that at index 1, we set the item icon to that potion image. And lastly we can go up
to our hatchet, press E. And you see we have our
hatchet item on our hotbar. So we set up a simple hotbar and
we can actually pick up the items and we'll show it on our hotbar. Now what I want to set up is
a simple selection system. So basically when I scroll my mouse
wheel up or down, I want to highlight the item that I have selected on my hotbar. So first things first, let's
actually head over to our main widget and the same sort of thing
that we did with this update image. We want to do it for
our borders right here. So we have these borders and basically I
want to change the color of this border to be yellow if we have that item selected. So the first thing that we need to
do is set these borders as variables. So if you select the border, you
want to check is a variable in here and that will actually allow
us to use it here on the graph. So now you can see we have border 72. So we head back over to the
designer, I'm going to rename this. So this will be Border 0. Then select this. Second border when I rename this change
that to a variable and rename this to border 1 and then select this last one
right here Change it up to a variable. This will be border 2. I'll save that head over to the graph
and in here right below our update image We can right click add custom
event and rename this to Select item and we want to add a new input
and this will just be a integer And we'll rename this to selected index. So sort of the same thing up here are
the item index that we have selected. And again, we wanna do
a switch on integer. So we want to do a switch on
int, we want to add those three pins, so zero, one and two. And in our case, we want to set
the borders to sort of yellow tint. So if we get border zero, we
can get that on the graph. We're going to drag off here
and do a set brush color. So we have set brush color. Hooked that up for zero, and we can
change this color to sort of this yellow tint like that, click OK, and then we
can copy this set brush color and paste it two more times, hook this up like so,
and for these other brush colors, we want to get border, border one, hook that up
for the target, and then we want to get border two, hook that up like so, OK? So depending on the item we have selected,
we'll set the brush color of the border to this yellow tint, and that will sort of
give it like this highlighted effect, OK? So now we need to add the logic to
select an item, so for that we'll head to our third person character,
and we want to add a scroll wheel event, so if I scroll up, it will
cycle through the items, if I scroll down, it will cycle backwards, okay? So in our third person character, we
want to add the scroll up and the scroll down for our mouse, so we want to right
click and search for mouse wheel up, so we have mouse events, mouse wheel up. And we also have mouseWheelDown,
so mouseEvents, mouseWheelDown. Then we want to add a couple of
variables to keep track of our selected index on our hotbar. So we want to, under the
variables, add a new variable, and name this to selectedIndex. And change this from an array to
a single, and change this from the structure to an integer, okay? So compile and save that. And then we also want
to add another variable. And call this maxInventorySlots. Okay, for however many inventory
slots that we have on our hotbar. So compile and save that. Now for this maxInventorySlots,
we want to set a default value. So select that, and the
default value will be 2. Because again, this is an array. So it starts at index 0. So we have 0, 1, and 2. So compile and save. So for our mouse wheel up event,
we're going to do a check. The check that we want to do
is we want to get our selected index, get that on the graph, and
also get our max inventory slots. So I want to check and see if
our selected index is equal. So we have operator equal. To our max inventory slots so off of
here We can do a branch and then we can hook that up for our press for our
mouse wheel up Okay, if it is equal to our max inventory slots That means we
can't scroll any further up if it is not then we can go ahead and increment
our selected index So you want to get the selected index and off of there? We can do a increment so we have
increment integer and that will add one to our selected index Variable plug it
up for the false and then to visualize this we could do a print string So do
a print string and we'll just hook up this value to our string Okay, just
to see what it looks like then for our mouse wheel down We want to check it
and see if our selected index is equal. And for this, we just want to check
and see if it's equal to zero because then we can't scroll any further down. So we do a branch. So if it is equal to zero, we
don't want to do anything because we can't scroll any further down. But if it is not equal to zero, Then
we can go ahead and scroll down. So we want to get our selected
index and do a deincrement. So deincrement integer. Select that, hook that up for false. And then we want to
print that to our screen. So do a print string and hook up
the value to our print string. Okay, so compile and save that. So now if I scroll up we should see
the value of our selected index. And we should see it go all the way up to
2, and then all the way back down to 0. So I hit play, I can scroll up, you can
see it goes all the way to 2, and if I scroll all the way down it goes down to 0. Selected index is 1, 0,
and go from 0 to 1, then 2. Okay, so you can see I
can scroll up or down. And it changes the value or
the selected integer variable. So now we can take that and feed
that into our widget to change the border and set that brush color to
whatever index that we have selected. So in our third person character,
we can just call that event that we created in our widget. So we want to get our widget
reference on the graph. And we have that select item event. So plug that in like so, then for the
selected index, we can take this value and plug that in for the selected index. Again, we want to do the same
thing down here, so take this, copy and paste it, hook that up. And for the selected index, again
off of this de increment, we can plug that in for our selected index. So compile and save. Now what we're going to see is
when I scroll, you can see that it changes the color of the border. But it's not resetting the other
ones back to the default color. Okay, so now it's all selected. So we want to go ahead and fix that. So in our main widget, under our select
item event, before we set the brush color to yellow, we want to reset all of the
other borders back to the default color. So we're actually going to take
all of this, and move this over. So before we do anything, we
want to set a brush color. So I'm going to copy and paste this over
here, and for this brush color, we're going to set this to a default color of
black and then change the alpha to 0. 5 and click OK. So that is the color that we have set
as the default for our border here. So we want to set or reset our
borders before we set the brush color. So for this first one here, we want to
set borders 1 and 2 to this black tint and then set border 0 to the yellow. So copy borders 1 and 2,
plug that in for the target. Let's plug in our execution and then for
this we can set border zero to yellow. Then for one we want
to reset zero and two. So copy and paste those. We can unhook these and copy and
paste our set brush, uh, color, so our resetting brushes zero and two
before we set border one to yellow. And then lastly, for border two, we
want to reset borders zero and one. Okay, so copy and paste that. Down here and then copy and paste
our set brush color, hook that up for two hook up border zero and one. So resetting that before we're setting
the brush color of border two to yellow. So we're basically
resetting the other borders. to the default color before we're setting
the selected border to the yellow tint. So compile and save. Let's go ahead and hit play. And now you can see I can scroll
up or down and you can see which index we have selected. We have index 0 selected, 1 or 2. Or we can scroll all
the way back down to 0. So it sort of gives us
this selected effect. Okay, so we have the ability to pick
up items and then we can also Move our mouse wheel up and down and pretty much
select which item that we want to use. Now what we want to add is we want to
add the ability to actually use items. So if I select this potion, I
want to be able to left click with my mouse button and use it. Also, I want to give the character
the ability to swap items. So for example, if I were to run up
to this book, I want to pick it up. On my hotbar, where I have it selected. And also, I want to go
ahead and swap items out. So for example, if I have
my book item selected here. If I pick up the potion, I want
to swap my book for the potion. So we're going to go ahead
and implement that logic now. So let's go to our third
person character blueprint. And in the event graph, over
here up at our pickup event. We're actually going to move this
pickup event logic into a function. So there's actually two different
ways that we can do that. We can create a function in here, or
you can select all the code and right click and do collapse to function. So if we do collapse to function,
that, what that will do is it'll go ahead and create a new function for us. And it will also add a input for
whatever nodes that we have hooked up. So you can see it added automatically
this input of the type S item structure. And we can go ahead and rename
this function to add item. And then for this input
we can rename this. But you can just leave that
as a new item, that's fine. And so in this function, if we
double click and open up, you can see that it has all of the
logic that we had outside of it. We have the add item, we're taking
that new structure, adding it to our inventory array, and we're
updating the image on our hotbar. Now, This all works pretty much
the same as what we set up. But what we want to set up is the ability
to swap an item so that basically before we add the item, we check and see, do
we already have an item at that index? And then if so, we'll swap the item and
spawn the other one back into the world. So we're actually going to go ahead and
delete all this so we can start out fresh. So delete that and compile save. So first things first, let's actually
select our inventory array and we're going to give this a three array elements. So we have index 0, 1, and 2. So we have a total of three
different array elements. Now the reason why we want to have these
array elements is because we're going to set them rather than add array elements. So it's sort of like setting a cap on
how many slots we have in our inventory. So now to actually set these
array elements, we're going to get our inventory array and we're
going to use the node setArray. Okay, so this array set array element. So this specific node allows
us to set a specific index that we have in our inventory. So for example, I'm going to
hook this up to our execution. And for the index, we want to
hook up our selected index. So this is the index
that we have selected. So get that on the graph and
hook that up for the index. For the item, this is
the S item structure. So plug in the new item for that item. Then lastly, we just
want to update the image. So we want to get our widget reference
and update our top bar image. So call that update image function. And then for the item index. We can plug in the selected index,
and for the item icon, we want to, off of our new item, we want to break
sItemStructure and expand this and plug in the item icon for the item icon. So compile and save. So now we've set up a pickup logic
that picks up the item at the specific index that we have selected. So for example, if I hit play,
if I move my mouse cursor to index 2, At the very right. If I pick up the book, you can see that it
picks it up at that selected index, okay? So I can select the first index,
or index zero, pick up the potion, it'll be added there. And then the last one,
I'll select it here. Now this also works for swapping. So technically, I could pick
up the book at the first index, and then pick up the potion. And now you can see that it
sort of swaps that item out. But what we need to add is we need to
spawn back the item that we swapped out and drop it back in the world. So the way that we're going to do that is
by spawning that actor back into level. We actually need to modify our
item structure and add another variable type inside of here. Okay, so we need to go back to our
content drawer, stock that in layout. Let's go to our structures and double
click and open up our item structure. And so we're going to add that one
last variable that I was talking about. So add a new variable in here
and this will be of the type BP underscore item, BP item master. And instead of an object reference,
we want to select the class reference. Okay, so select class reference. So it should be BP item
master class reference. And just rename this to item class. So now save that. Now if we go back into our
third person character. We now have that item
class, class reference. So we're going to use this to actually
spawn the item back in the level. And also we're going to check
and see if we have an item inside of our inventory array. If that class reference is valid. So actually we need to
recompile the blueprint. So that we have that
new structure variable. So we have that item class. So basically before we do
anything we want to do a check. Check and see if the item that
we're adding at that selected index. If there's an item set inside of here. So the way that we'll do that
is we'll check and see if the item class is set to none. Or if there's something actually in there. So first for our add item, we're
going to get our inventory array. Do a get, get a copy. And we want to get it
at our selected index. So get this selected
index and hook that up. And then we want to break the structure. So do a break sItemStructure. Expand this and we'll want to
get the item class, and off of there we'll do a isValid class. So we'll check to see if it's a valid
class, and if so, we'll do a branch. Branch. And let's hook this up for the condition. So basically, if this is false,
then we'll just add an item. So I'll actually just plug
this into our setArray element. Because we don't have to spawn
any item back into the world. But if this is true, that means that
there is an item at that inventory slot in our inventory array. So that means that we have to
go ahead and swap the item or spawn it back into the world. So we're going to do a spawn actor,
spawn actor from class, and then we can hook up the class from our item class. And that will go ahead and
spawn that actor into the world. Now we have to give a spawn transform
of where we want to spawn the item. So what I'm going to do is
in our viewport, spawn it in front of our character. So I'm going to select our
character and add a new component. So let's click the add icon
and search for a arrow. So we have arrow component,
select that and move that forward. And we're going to rotate this 90 degrees. So it should spawn the item sort
of right in front of the character. So compile, save. It's giving us this error. Let's go back to our add item function. Okay, it wants a spawn transform. So we're just going to right
click the spawn transform and do split structure pin. Then if we compile and save, you
can see that error goes away, but we need to hook up a location. So we want to get that arrow component
that we just added, get that on the graph, and then we want to get the location. So drag up there and get world location. Okay, so transformation,
get world location. So plug the return value into
the spawn transform location. And that will go ahead and spawn
that item back into the world. And then, of course, after that, we want
to go ahead and set the array element. So we can go ahead and add
the item at that index. So. That is our add item, so to recap, we
are getting the item at our selected index, we're checking to see if there's
an item inside of there, if there's a valid class, if so, we're spawning
the item that we have at that index back into the world, and then we're
going to go ahead and add the item that we're picking up at that array element. Now, if we were to test this out, it's
not actually going to spawn the item back into the world, because we haven't set... Our item class reference, so we need to go
ahead and set that item class reference, so we want to go to our blueprints and
to our items, and we want to open up our item health potion, and once you
open it up like this, sometimes when you open up a blueprint it will show This
view, which is just the default value. So if you want to go back to the
default blueprint view, you can click this open full blueprint editor, and
that will pull up the normal blueprint editor view that we're accustomed to
now in the class defaults under the item info, we want to, we actually
want to recompile our master blueprint. So head over to your BP item
master and hit compile and save. And now if we head back over to the
children class or the item health potion, we can now see we have that item class,
uh, variable inside of our item info. So for the item class, we want to hit
this dropdown and we just want to set it. Basically to itself. So for this item health potion, we want to
set it to our item, BP item health potion. It's basically like setting
a class reference to itself. And then we want to go ahead and do
this for all the other, uh, blueprints. So we have our item hatchet,
so double click, open that up. And we can also edit the class defaults,
or the item info, inside of this view. So in this item info, under the item
class, we can hit this dropdown. And this is our item hatchet, so we
want to set it to our BP item hatchet. Compile and save that close out of there
And then we want to get our item book and in the item class We want to hit the drop
down and set it to our BP item book So hit compile and save and now that should
be good to go So now if we go ahead and hit play we should be able to pick up an
item So I'm gonna pick up this book at the first index and then if I pick up this
potion You can see that it swaps it out and spawns that item back into the world. So I have the potion on my hotbar, and
I have the book spawned in the world. So if I go back to the book and
press E, you can see that I swapped the potion for the book, and the
potion is spawned back in the world. I can do this for other items like the
hatchet, and swap that out like that. Now I want to add a little bit of
physics to these items, so that they're not just floating in the world. So if we go to our item master, our BP
item master class, we can select the static mesh, and in the details we can... Hit simulate physics. So we're simulating physics for our
static mesh component So now if we hit compile and save and go back into the
world You can see that our items have physics So I can go ahead and pick up
this book and then if I swap it out for the potion you can see that It has sort
of this drop effect So it has sort of physics enabled and we can swap out the
items like so so now we have a basic item swapping logic Now what I want to add
is the actual ability to use the items. So for example, when I click on this
health potion, I want to consume the item and say restore some health. If I click on this book, I want to pull up
the text so I can actually read the text. And then if I pick up this hatchet
and click on it on my hotbar, I want to be able to equip a hatchet item. To our players hand. So let's go ahead and set up the use
item logic So we can actually use the items on our hotbar so let's go
to our third person character and into our event graph and what we
want to add is a Left mouse button. So basically when I click on my left
mouse button, we're gonna use the item at that hotbar index So I'm gonna right
click and search for left mouse button. So we have mouse events left
mouse button Now we want to add a function called useItem. So let's add a new function and
name this to useItem and we're going to add an input and change this
input type to our item structure. So we have our S item structure. And I'm going to rename this to item info. So compile and save that. Now in our event graph, if we go back to
the event graph, we can call that use item function and hook that up for the pressed. And then to get the item info at
our selected index, we want to get our inventory array and do a get. So array get, get a copy. And then we want to get
it at our selected index. So get the selected
index and plug that in. And then for the output, we can
plug that in for our item info. So basically when we left click our
mouse button, it's going to get that item at our array index or wherever
we have it selected on our hotbar. Then it will feed that
into our use item function. So we can double click, open that up. And so inside our use item,
we want to drag off here and do a break S item structure. And now that's where this item type. enumeration comes handy. So off of this item type, we
can do a switch on e item type. And now we can set up different logic
depending on whatever item type it is. So if it's a consumable,
I can consume the item. If it's a equipable, I can equip
the item to my player's hand. And if it's a readable, I could show
some text on the player's screen. So let's hook up the execution pin here. So now what we want to do is we want
to Instead of putting all the logic inside of here, we're actually going
to add some functions, that way it'll keep everything nice and clean. So add a new function called consume item,
and then we're going to have a input. So add a new input. It'll be of the type S item structure,
and we'll just rename this to item info. And then let's go ahead
and add another function. So be called equip item. And we'll have another inputs
of the type S item structure and just rename that to item info. Okay. And then add one last function. So be called read item and
then add another inputs. For the type S item structure and
just rename that again to item info. So compile and save and head
back to the use item function. So in here we can call those functions. So you can actually put a
function inside another function. So for example, I can call my consume item
function inside of the use item function. So I can get my consume item,
hook that up for my consumable. And then for the item info, we
can plug in the item info like so. So we just want to do this for
all of our other functions. So get our equip item function. Hook that up for the equip,
equipable, and plug in our item info. And lastly, call our read item function,
hook that up for the readable, and plug in our item info to the item info like so. So now, depending on the item type,
we will call a different function depending on the item type enum. So if it's a consumable, we'll
call the consume item function, if it's equipable, we'll call the
equipable item function, and so on. So now we need to set up these functions. So first things first, let's go ahead
and set up our consume item function. So let's double click it and open that up. That will open up the
consume item function. And in here, basically what the consume
item function will do is we're going to add sort of a health variable to our
player and it will restore some health. to our player's health bar. So we're going to consume that
potion item and it will just restore some health to our player. So first things first, we need to actually
add a health variable for our player so we can keep track of the player's health. And we're actually going to be
adding a health bar as well later on. But first let's add a
variable for our health. So a new variable and this
will be called health. And we want to change this to a float. So compile and save that. And now in the default value, we can set
this to, let's actually set this to 10. So we don't want it to be a
hundred HP because the consume item will restore health. So I'm just going to set
our players health to 10. And then for our consume item, we want
to get our item info and do a break S item structure and expand this. So we have this damage variable. Now for our consume item, we're actually
going to be using this damage variable as. The variable to restore health. Because we set that early
on in this tutorial. We were using the damage for
the amount of health to restore. So we're going to get our
health variable on the graph. We're going to do a add. So we have operators add. And we're going to add that
by the amount of damage. So take that and add that like so. And then we just want to clamp this. Because we don't want the player to
restore more than 100 HP for their health. So off of this I'm going to do a clamp. Clamp float. So we have this clamp float and the
minimum will be zero and the maximum will be a value of a hundred So we
can't heal more than a hundred HP. Then we just want to set our health. So get our health And do a set hook
that up for the value and we just want to hook up our execution pin
like so and Then we could finally just print this off to our screen for now. So do a print string And hook up
the health into the end stream. Then lastly, we want to go ahead and
remove the item from our inventory. So basically when we consume
an item, we want to remove the item because we consumed it. So it's like a one time use only. So to do that, to clear that
inventory array, we want to get our inventory array on our graph. And we're going to do a set array. So setArrayElement, and for the index,
we want to hook up our selected index. And instead of hooking up
anything to this item, we're just going to leave this as blank. And what that will do is it will
set all the values to nothing, okay? It will basically reset that
ArrayElement to an empty ArrayElement. And then lastly, we want to actually
update the item icon on our hotbar. Because if we were to consume this item... It's going to remove the item at that
inventory array, but we need to actually update the item icon on our Widget. So let's go to our W main widget
and go to the graph and we need to add a event that will remove the
item or Reset this image back to the default if we delete that item. So in our graph we want to Right click
and add a custom event, and this will just be called remove image, and we
want to add a input of the type integer, and rename this to selected index. So compile, save, and just like we
were doing up here, we want to do a switch on integer, so do a switch on
int, and then we want to add those three indexes, so index zero, and
One and two, and then basically we just want to set the image back to
the default style or just reset it. So if we get our image zero on the graph,
we can do a set brush from texture. So set brush from texture. And if we just leave this as
empty, that will just reset the image to the default style. So hook that up for index zero. So we're setting the brush for index
zero and we want to get image one and do a set brush from texture
and hook that up for index one. And then lastly, we want to get image
two and again, do a set brush from texture and hook that up for index two. So we're basically just
resetting the image back to this default style, depending on
whichever index Have selected. So now we can just call this remove
image in our third person character and in our consume item function We
just want to get our widget reference. So we'll get our widget reference And
then we can call that remove image function and Then for our selected index,
we just plug in our selected index. Okay? So that will go ahead and ensure
that we remove the image or reset the image wherever We're
consuming an item on our hotbar. So now we should be able to test this out. So in our event graph, basically what
we set up is our left mouse button. So when I click on my hotbar at the
selected index, it's going to get that array element at the selected
index and call our use item function. It's going to pass that item info over
and depending on the item type that we have selected, say it's a consumable, it's
going to call our consume item function. And again, pass that item
info into that function. And then with that item info,
we're going to get things like the damage, which is technically
how much health we should restore. We're going to get our health
variable, which is 10, and add that amount that we want to restore. We're going to make sure that we clamp the
value and not restore more than 100 HP. We'll set that and print
it off to the screen. And then finally, we're going to... Delete that item, array element, or
reset it back to an empty array, and then remove the image on our widget
so that we can see that we removed that item or we consumed that item. So now if we hit play, we can run
up to our potion and pick that up. Now if I click left mouse
button, you can see that our value is 40 up at the top left. And so we started at 10
HP, but we restored 30. So you can see our total HP is 40. And also it removed the
item at our selected index. So let's actually add a health
bar widget so we can visualize our potion restoring health. But as you can see, it removed
the item from our health bar. And we know that that is all working. So to add our health bar, we're going
to actually go to our main widget. And designer, and this is going to be the
same exact way that we added our health bar in our blueprint for beginners video. So in our palette, we're going
to search for a progress bar. So we're going to select the progress bar
and just drag it onto our canvas panel. And we can just scale this up. Okay, and the percent, so in the
details, if you have it selected, this percent is what actually
drives the progress bar percent. So you can see a value of 1 is full HP, 0. 5 is, you know, about half
HP and all that stuff. So first things first, let's
actually anchor this to our bottom left part of our screen. So make sure you select the
progress bar and in the anchors up here, we want to anchor it to the
bottom left part of our screen. Then we want to just bind on this percent. To the health values in our
player so to do that over here. We have this nice bind Button so for
our percent we can click this Drop down and create a binding so click on that
What that will do is it will create this function get percent and it will return
the value right here So we can basically set up inside of this function get our
players health and return it As a value here and it will go ahead and bind that
to our percentage for our health bar. So we want to right click and get
owning player, get owning player pawn. And then from there we
can cast to our character. So we can do a cast to
third person character. And for our third person character
we can just get our health. So get health. Default get health. And for our return value, we don't
want to actually plug this in because this is a value from 0 to 100, and
our percent is a value of 0 to 1. So we need to basically shift the
decimal point over, so that we can have this be clamped at a value of 0 to 1. So we can do a multiply, so operator
multiply, and we can multiply this by 0. 01. And plug that into the return
value, and then just hook up our execution pin like so. So compile, save, and now, if we head back
to our designer, we should be good to go. So let's hit play, we have our health bar,
you can see that we're currently at 10 HP. So let's go ahead and pick up
this potion, if I consume it, you can see that we now consumed that
health potion and it restored 30 HP. So we're sitting at a total
of 40 HP on our health bar. We'd even get this health potion and
duplicate it a couple more times. So if you hold alt on your
keyboard and drag, that will go ahead and duplicate the item. So I'm going to duplicate
it two more times. Hit play. Go ahead, run up to it and consume it. And pick this up and consume it again. And then again, pick
this up and consume it. So now we're at 100 HP. So that is our consume item function. So we can consume our health
potion and it will restore some health to our player's health bar. Now let's go ahead and set up the other
functions for our item readable and also our equippable item like our hatchet. Let's go back to our third person
character and to our use item function. So we need to set up our equip item,
so let's go ahead and set that up next. So double click it and open that up. And in here. What we want to do is we
basically just want to attach the hatchet to our player's hand. So the way that we can do that is off
of this item info, we can do a break S item structure and expand this. And we have this static mesh or
this mesh variable that we can use. So now we want to go ahead and
actually add a static mesh. So if we head over to the viewport, we
want to add a static mesh component. For our character, that way we can
attach that to our player's hand. So, in our viewport here, in
the components, let's actually select our character's mesh and
add a static mesh component. And we can just rename this to weapon. And then just compile and save that. And then if we head back over to our
equip item function, we can get that static mesh component, or our weapon. And do a Set Static Mesh. So we have Static Mesh, Set Static Mesh. And we can basically set that mesh to the
mesh of the item that we're equipping. So hook up the execution pin like so. And then finally what we want
to do is we want to attach this weapon to our player's hand. And so to do that we're going to use
the Attach Component to Component. So we want to get our weapon component. And do a attach component. Attach component to component. So for the target component,
that will be our weapon. For the parent, that will be our mesh. So we want to get our mesh. Plug that in like so. Then for the socket name, we
want to actually add a socket. So sockets are again what you'd
use to attach things like weapons. armor, any sort of
equippable to your player. So we need to go to our player character. So head over to the viewport
and select your character mesh. And to browse to that we can go to
the details and click on this little browse icon for our skeletal mesh asset. And then we can double
click to open that up. So that will go ahead and pull
up the skeletal mesh editor. And then we want to head
over to the skeleton. So click on this little skeleton icon. That will pull up the actual
skeletal mesh and all the bones. So over here on the left we
can see all the different bones that make up this skeleton. And in our case we want to look for
the hand R bone or the right hand bone. So it should be this hand underscore R. And so with our hand R selected we can
right click and select this add a socket. And I'm going to rename this Hand R
Socket, so double click on that, I'm going to rename this to Weapon Socket. And then we can actually add
the hatchet to this, so we can modify the scaling and location. So right click that Weapon Socket, and
we should be able to add a Preview Asset, and over here we can search for Hatchet. So we have that Static Mesh Hatchet. As you can see it's very tiny,
so we can actually scale this up. I'm going to decrease
my camera speed here. I'm going to press R on the keyboard. Now I can scale this hatchet up. I can press E to rotate. I can rotate this 90 degrees. I press W, I can move it around. So basically I'm going to
sort of move it like this. Sort of place it in the character's hand. And I'm going to turn
off rotation snapping. So if I rotate it, it should
get a more smoother placement. And we're just going to, you know,
roughly place it in the character's hand, something like that. So save that. We're going to copy
the weapon socket name. So double click and copy this. And let's go back to our
third person character and into our equip item function. And now we should be able to type
in or paste that socket name. Uh, that we're going to use. So I'm going to paste in
the weapon socket like so. And for our location rule, I'm
going to change this from keep relative to snap to target. Snap to target. And snap to target, okay? So for location, rotation, and
scale, we'll just do snap to target. So compile, save that. Now we should be able to
see this work in action. So we're equipping the item. We're setting the mesh component,
and then we're attaching that to our player's hand at the weapon socket. So let's go ahead and hit play here,
and run up, pick up our hatchet. And then if I left click, you can see
that we now equip that hatchet to our player's hand, because we're setting
that static mesh component, and we're attaching it to that weapon socket. That's on our player's hand, okay? Now one thing that you're going to
notice is if I try and equip this other book, you can see that we still
have the hatchet equipped to our hand. So no matter what item I swap
out, you can see that we still have that hatchet equipped. So just a little bug that
we're going to have to fix. Let's go ahead and actually
fix that right now. So let's go to our third person character. And to fix that little bug, we just
want to go to our add item function. And basically, if we have a item equipped,
we want to do a little extra check to see if we have that hatchet equipped, and
then if so, we can de equip that hatchet. To do that off of this true,
so if it is a valid class, that means that we have an item in our
inventory slot that we're picking up. Then we want to do an additional check to
see if that item is an equippable item. So let's go ahead and
actually select all of this. And move this over. So that additional check, we
just want to get the item type. And check and see if that is equal. So do a enum. Equal enum. We want to see if that is
equal to a equippable item. So off of this true we
can do another branch. Do a branch. Let's hook that up for the true. So if that is true, that means that
we have an equippable item equipped. If it is not true. For the false so we can just plug it
back into our spawn actor So now we want to add a dequip item a function
up here that will basically just reset this weapon mesh to nothing
So let's add quickly a new function. So click add function. Just call this dequip Item and
then in here, this will be really simple We're going to get our weapon
mesh and do a set static mesh. Okay, so we're just going
to set the static mesh. And rather than plugging anything in
here, we're going to leave that as empty. So that will basically just reset
the weapon mesh to be empty. So compile, save that. Let's go back to that add item function. And now we can call that dequip item. So drag and drop that on the graph. And then for the true,
we can hook that up. Dequip the item, and then of course you
want to plug that back into the spot actor so we can continue to swap out the item
and add the item that we're picking up. So now we should be fixing that bug
that we have with our equipped item. So if we hit compile save, hit play,
I can pick up the hatchet, equip it. So if I click on it,
that'll equip the item. Now if I go and swap it out for
a book, you can see that it de equips the item from our hand. And again I can pick up the
hatchet and re equip it. Or swap it out for a potion and you
can see that it de equips that item. So just a little bug that we
can fix by de equipping the item first before we pick it up. Now the last item that we want
to set up is our readable item. So when I pick up this book and I
left click, we want to basically have sort of a little widget. That looks like a book on our screen with
some text that we can read from our item book so let's go back to our third person
character and Go back to our use item function So we set up the consume item
the equip item now, let's go into our read item function So double click and open
that up now in here what we want to do is we need to actually go ahead and add that
book widget inside of our Main widget, so let's go to our W main widget and in here
We're going to add a simple book widget or a little border that sort of looks
like a book and then just some text inside of it, so let's go ahead and search for
a vertical box So we have vertical box. Let's go ahead and drag that onto our
canvas panel and scale this up Move this around like so And then we're
going to add a multi line, and we're going to add a text box multi line. So drag that and drop that
into the vertical box. Actually, first things first,
select the vertical box. So make sure you have that
vertical box selected. And we're going to anchor
this to the center. That way it'll be in the
center of the player screen. Then select the multi
line editable text box. We want to set that to fill. So I'll fill the entire box then for
the text we can type in, you know, test one, two, three, four, five testing
this multi lined text box Okay, so you just put in a bunch of random text. We actually can barely see that text
on there So we need to change the style So for the style you can go
into the details and expand the style and then over here we want to change
things like The foreground color, background color, and all that stuff. So I believe the foreground color,
if we change that, that actually changes the color of the text. So I'm going to set that
to a white, uh, color. And for the background, I'm going
to change this to a black tint. So it should be like that. Then we want to go ahead and scale up
this font, because it's a little bit tiny. So for the font style, we want to
go to this text style, expand that. We have font. I'm going to change the font family
to this font that we have here. And then I'm going to scale up the
font size, you can change the size, I'm going to leave that as 26. I think that should be good. So as you type more words in here,
you can see that the text wraps. So I can do testing the
text wrapping on this box. So you can see this allows us to
have, you know, multiple lines. And so this will be perfect
for our book text, okay? So compile and save that. Now if we were to hit play, this
widget is going to be shown by default. Now we don't want that to happen, we
want to have it be shown if the player left clicks on the book on their hotbar. So let's go back to our main widget. Now to show or hide this
widget, we're going to... Actually head over to the graph and
we can close out of this get percent function so you can close out of that
and head over to the actual event graph and so we can basically get that multi
line text box on our graph and set that to visible or hidden also we want
to edit the text because we want to set The text to the text that we have
inside of our book item or item book. So on the graph we want
to add a custom event. Add custom event. And this will be called open book. And this will have one
input of the type text. And just rename this to book text. Okay. So compile, save that. We want to get our multi line
editable text box on the graph. And then we can do a set text and
if you scroll down we have this widget set text multi line text box. Okay, so this is the one that we want. Then for the in text we can just
plug in the book text like so. Then lastly we want to make
this visible on the screen. So we want to get our multi line
text box and set this to visible. So, under the widget visibility
we want to set visibility. And we want to set that to visible. Now by default, we also
want to set that to hidden. So in the designer, we want to
select the multi line text box. And in the details panel, if you
scroll all the way down to behavior, we should have this visibility. We're going to set this
to hidden by default. So this multi line text box,
we're going to set that to hidden. And then in the graph, we
have that open book event. That will set that to visible now We also
want to add a closed book or hide book event that will basically set that to
hidden So down here when a right click add custom event this will be called hide
book and then for this we're just going to get our multi line text box And call
the set visibility Widgets visibility and set that to hidden So the open book
will set the text, set the to visible. The hide book will just
set that back to hidden. So compile, save that and we
now have our book widget set up. So now we just need to call those events
inside of our third person character. And in our read item function. So in our read item function we're
going to add actually a new variable. So in the variables
let's add a new variable. And call this is book open question mark
and changes from my float to a boolean. So compile and save that. Basically you want to keep track of
whether or not our book is open or closed. Or whether or not it's
shown on the screen. So I'm going to get that
is book open boolean. And off of here we'll do a branch. Hook that up like so. Okay and if it is open,
we'll hide the book. If it is not open, We'll open the book. Okay. So to actually open the book, we
want to get our widget reference and call that event that we created. So let's get our widget reference
and call the open book function. Let's hook that up for the false. Then for the book text, we can, off of our
item info, do a break as item structure. And if we expand this, we
should have an item text. So for our item book, we
typed in this item text. So we're going to use
that for our book text. Then for our hide book up here, we want
to again, get our widget reference. So get that and call our hide book. So hook that up for the true. And then lastly, we just want
to set this Boolean to false up here and true if we have it open. So get our isBookOpen and set that. So if we are opening the book, we're
setting our isBookOpen to true. If we're hiding the book, we're setting
our isBookOpen back to false, okay? And that will allow us to
open or close the book. So sort of like a toggle. So compile and save that. So now we should be able to test this out. So when we use the item, we're going to
call our Readable or read item function. We're gonna check and
see if the book is open. If it is not open, we're gonna call the
open book inside of our widget, which will basically set it or set the widget
to visible and then also set the text of that multi-line text box to the book text. So now let's go ahead and hit play. Let's go run up to our book
and press E to pick it up. If I equip it, you can
see testing 1, 2, 3. This is. Some text inside of this book if I click
on it again that will go ahead and hide the book text So basically that is our
simple readable item I can toggle it to read the contents of the book and
I can hide it to hide the contents of that book So that is pretty much all
the different items that we've set up. We set up our hatchet item That we
can equip You can swap it out For our potion, we can consume our potion
item and that will restore health. And then we have our readable item
that will pull up a simple book widget with some text inside of it. So to recap, in this video we covered
over some of the different data driven variable types inside of Unreal Engine. Things like enumerators,
structures, and arrays. We went over what are functions
and how to use them to save time and optimize our blueprint graph. And we also applied all of that knowledge
by creating a simple inventory system that features different pickup items. Things like a hatchet that we can
equip, a potion that restores health, and a book item that we can read. All of the items are designed
to inherit pickup logic. from the master class, which is the
preferred design method for blueprints. Now this is the second video in my
blueprint for beginner series, and I will be making a follow up video or a
third and final video for this series called blueprint for advanced users. So in the blueprint for advanced users
video, we will cover over some more advanced topics, things like what
are blueprint interfaces, and how to effectively use them, and so much more. So if you don't want to miss out
on that video, make sure that you hit the subscribe button
with the notification bell. So you don't miss out
on any future uploads. Also leave a like on the video and comment
down below if there is something in particular that you want me to cover in my
blueprint for advanced users video or in any future tutorial here on the channel. Also, if you appreciate the
free tutorial series, and if you are eager to learn more. I recommend you check out my premium
courses on my website, smartpoly. teachable. com. If you are interested in making games
inside of Unreal Engine, luckily for you, I have a complete multiplayer
survival game course where we create a complete multiplayer survival
game from scratch, and we'll be adding more courses in the future. So chances are if you're watching
this video in the future, you can check out my website, smartpoly. teachable. com to check and see if
there's any new courses. Anyways, I hope you enjoyed
the video, and as always, I'll see you guys in the next one.