Unreal Engine 5 | Blueprint For Intermediate Users

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys and welcome to the unreal engine 5 blueprint for advanced users this is the follow up video to my unreal engine 5 blueprint for beginners and i highly recommend you watch that video first before you try and follow this one because i teach you the basics of blueprints and how to use them in this video we will go over some more advanced topics in blueprint such as enumerations structures and arrays and we will use all three of these to create our very own simple custom items inventory system that you see here in the video so with that being said let's go ahead and get started alright so the first thing that you'll need to do is go ahead and download the project files the link will be in the description below and obviously if you have unreal engine 5 installed early access go ahead and launch then we're going to head over to games and create a third person project we can just name this blueprint part two go ahead and click create all right so first of all we're going to talk about the fundamental parts of blueprint such as variables and more specifically enumerations structures and arrays so first of all we'll start with the enumeration so if you remember in our character right click edit third person blueprint so this is our third person character if we remember from our last video we created all sorts of different variables and in fact if i create a variable here and we click on the variable type you can see all the various variable types now there are actually these other variable types we have enumerations here object types interfaces and structures and what we're going to be focusing on is enumerations and structures as well as arrays in this video so first of all let's start with an enumeration go to your content browser create a new folder and we're going to name this underscore main just so we can keep our little project here organized and in our main folder we'll right click create a new folder called enums all right and we can double click that folder and in here we're going to create our first enumeration so if we right click we can go to blueprints here and you're going to see here we have blueprint class blueprint function library blueprint interface blueprint macro library enumeration and structure so we're going to create this enumeration so we can name this test enum we can double click and open it up so what you see here is the enumeration creator and basically we have our numerators so these are the list and then the description for each numerator so let's go ahead and create a new enumeration in here so we click this new button and you're going to see the display name and the description so really all that matters is the display name so in this case what we want to do is type in is walking and then we'll create another one and then type in here for the display name is flying and then click new and type in is swimming and finally click new and maybe we'll do is sitting so basically an enumeration is simply a user defined option so it's like sort of like an option menu and to see this option menu and to set it what we're going to do is go to our third person character and go to our variables so we can go ahead and create a new variable name this character state enum okay so in here we're going to go over to the variable type and here we can search our test enum test enum so right there click on that and you're gonna see it's of the type enumeration and once we hit this compile and save button it will let us set the default value so this is basically what enumeration is if you click this down button you're going to see the options that we defined we have the is walking is flying is swimming or is sitting so basically this is what an enumeration is it's a list of options that the developer can define and you can use this in pretty much any any part of your game any part of your game that you want some sort of custom variable that allows you to have different options alright so this is great and all but how exactly do we use this in our game so we'll go ahead and show you how you can really quickly utilize this in your game okay so what we'll do is right click and add a f key so when we press f what we want to do is drag click on our test enum and drag it onto the graph and we want to get character state enum just like that and so what we can do is we can left click off of this node and type in switch on test enum so you just type in switch and select this and what you're going to see here is the different settings that we have so first let's hook up the pressed execution pin to the switched on test enum and what you're going to see here is basically when we press f depending on what we've set our variable type here depending on our character state you know so you can see is walking if it is set to is walking it's going to fire off this execution pin right here all right and if we were to set this to is flying it's going to set this execution pin right here so that means that any logic or any nodes that we put past this are going to fire depending on whichever setting that we set it to so let's go ahead and test this out so is walking what we can do is hook up a print string so remember this is where we can print stuff to our screen so we can quickly debug and know what's going on so what we want to put in for here is character is walking okay and we'll go ahead and copy and paste this ctrl c ctrl v and hook up this is flying and changes to character is flying and we'll go ahead and do the same for swimming hook that up character is swimming and of course i just realized i spelled the swimming wrong so you can actually go back and test enum and fix that save and it's going to change it and update it right there and then character is sitting and just like that okay so right now our current state is set to is flying so if we go and hit play we can press f on our keyboard and you see in the top left character is flying okay so we can go ahead and basically add another key and modify our current state so we can modify this enumeration and it will fire off different logic so for example we'll add a e key scroll up here okay so when we press e what we can do is drag off of our test enum here onto the graph and click set character enum and we'll hook up the pressed here and we'll set this to is walking just like that okay and then we'll add another key like the q key and we'll drag our character state enum and set this to is swimming okay so if you remember we press f to print our thing e now we're characters walking cue now our character swimming we can change our enumeration to walking q we can change our enumeration to swimming so this is basically enumerations in a nutshell you have these user-defined settings that you can create and you can do a switch on enumeration to have different logic based on this user-defined setting all right so we can go ahead and delete all this and delete our character state enum and what we're going to do now is create a new folder called structs or in this case structures so in our structures folder we can right click and we're going to blueprints and down here at the bottom we have structure so we'll go ahead and click on structure okay and what we want to do is rename this to test struct and then we can go ahead and double click it to open it and in here you're going to see the structure creation basically it's the same as the enumeration but in this case a structure is essentially a group of variables so you can see here we have one variable which is a boolean and so basically what we can do is we can create a group of variables and what we can do is add a new variable here first of all we'll change the first one to say text and what we can do is change this to player name so this next one we can change this we can leave it as a boolean we put something like is dead create a new variable maybe we want to create it as a float and name this to health then we'll add another variable changes the type integer and change the name to level and then finally one more variable we can change this to the type of our test enum and we can change the variable name to character state so if we save that we'll go into our third person character and we'll add a new variable we're going to name this character struct just like that and in the variable type we're going to change this from byte to test structure what we named it here and then we can compile and save it so here you're going to see the default value and if we actually expand this going to see all the different variables that we defined so we have the player name which is a text so we can enter in smart poly whatever your name is is dead is a boolean so we can check true or false health we can set something like 100 hp a level we can set to maybe level 25 and then character state you can set is walking is flying swimming sitting so basically this a structure this is a group of variables we have the text variable the player name is dead which is a boolean health which is a float level which is an integer and character state which is our enumeration custom enumeration with different states so essentially that's what a structure is it's a group of variables to store data for your game so we can actually go ahead and take our character struck here and drag it onto our graph and click get so what this will allow us to do is to access all this data here that we've added so to do that what we want to do is add a f key and when we press f we want to print our stats so we want to first drag off of our character struct and you're going to see here at the very bottom we can do break and so we're going to click on break test struct and what you're going to see here is if we expand this little down arrow you're going to see all the different variable types that we've set here in our character struct so you can see we can get the player name we can get if they're dead or not their health their level their character state and basically you can check and do certain functionality so if remember a boolean is a true or false so we can drag off of here and do a branch when we press f hook this up to our branch and check to see is the player dead or not if they're not dead we can go ahead and do a print string and print out their stats so in this case we can print out their name and you're going to see is convert the text to the string we can copy and paste this and we can print out their health and then we can also print out the characters level and then finally we can print out our character's state so you can see here when we press f we're going to get the structure we're going to break the structure so we can get all the data and access all the variables and then based on some of the variables on here if the player is not dead then we want to go ahead and print all the information out so if we hit play we hit f going to see our current state is is walking our level is 25 hp is 100 and our name is smart poly so that is one way that you can access the variables in a structure another thing that you can do is you can actually set the variables in a structure and to do that you would simply take the character structure set the character structure and drag off of it and what you want to do is right here make test structure so if you hit this little expand down button you can see we can actually make and set all of the variables in here so actually what we want to do is we can go ahead and alt click to unhook that drag this up here and hook up the what we want to do is we want to set our character struct to something else so for example we could do something like joe is dead is true their health is now zero their level is 30. and their state is sitting then we can hook this up to our branch here and if we hit play gonna notice nothing's happening and that's because we actually hooked up the is dead and nothing's happening if the character is dead in this case our character is dead so we can either switch the pins there or we can uncheck this that will let us print it so i'm just going to go ahead and uncheck that and then if we hit play we can hit f and you see the structure data is being set so we're setting it to joe hp is zero level is 30 and state is is sitting so you can see we can set the variables in a structure and we can also get the variables in a structure okay so another thing that is useful to note is let's say you don't want all these variables you can actually hit this down arrow right over here and unpin some of these so we'll hit alt and click some of these let's say we only want the player name is dead and health what we can do is click hide unconnected pins and will automatically hide the pins that we don't need or we can check the pins that we do need so those will allow us to get the data that we only want and modify the data that we want to modify so that's a brief overview of structures so now what we're going to go ahead and do is delete all this compile save close our test structure and in our content browser i'm going to go ahead and hit this dock and layout we're going to create our item structure as well as our item enumeration so first of all we go back into our main folder in our enums we're going to right click add a new blueprint down here enumeration we're going to name this to item type enum and double click this to open it up we're going to add three new enumerators so up here we're going to rename this to consumable so these are the different item types first we have a consumable item so like a health potion that can restore health then we have an equippable so this is like an item like a weapon or sword okay and the third one is a readable okay so this is our item type enumeration basically we have the different item types we have consumable equippable and readable and based on these different item types we can do different logic so let's go ahead and create our structure our item structure with that item enumeration so back in our main structs we're going to right click and add a blueprint structure and we're going to name this to item struct go ahead and double click that and in our item structure we're going to define all the variables that we need for our item information so we can add things like the item name the mesh the amount of damage that it could do the item icon and things like that so the first variable in this case is our item type enumeration i'm going to change the name here to item type then we're going to add another variable and this is going to be static mesh so if you scroll down here you're going to see object types and we're going to click on the static mesh object reference i'm going to change the name here to mesh and what a static mesh object reference is is essentially we can set this mesh reference here to anything we want to any in this case static meshes that we have in our game so we have a cube a cone any static meshes that we import into our game we can set this variable reference to that mesh that is essentially what a object reference is all right next up we'll create another variable and this will be of the type integer i'm going to name this to damage so this could be if we had a weapon we could set the damage here we'll add another variable and we can set this to text and we'll go ahead and rename this to item name so this will be the name of our item and we'll add another variable called texture [Music] 2d and you're going to click on here the texture 2d object reference i'm going to rename this to item icon so the item icon and just like our static mesh object reference in this case it is a texture object reference so we want to set the item icon texture okay and we're going to add two more variables first one will be of the type text and we can rename this to item text so in this case for item readable we can put information here that's going to be either about the item or in this case in the case of the readable item like a book we can put the text that's going to be in the book in this particular variable right the last variable we're going to hold off on creating because we actually need to create the blueprint for it but basically we've created our first item structure here and so you can see here we have the default value values so we have our item type our mesh the damage the name icon and item text so we can go ahead and close out of that and now what we want to do is we want to create our item blueprint so if we go back into our main folder we're going to right click and add a new folder called blueprints we're going to right click and add a new blueprint blueprint class and this is going to be the type actor because we want to create an actor such as an item that can be spawn into the world so we'll go ahead and create a new actor and we're going to name this to bp underscore item master okay bp because it's going to be blueprint and then the name item master because it's going to be the master class so if we double click on it all right so now that we're in here what we want to do is create a new variable and we're going to name this to item stats okay so we want to change the variable type here from boolean to our item structure okay so we can compile and save and now we've created our item master class with our item structure variable and in the default value here you're going to see all the information we're going to see all of the stats that we can set for our item so we can set the item type to consumable equippable and set the mesh of the item the damage all that good stuff in this structure so we actually don't want to set the variables in our master class just yet so let me show you what we have to do next so next let's actually add a mesh for our item blueprint and a spear collision that we can use to allow the character to pick up the item so first we want to do is click add here and search a static mesh so we'll go ahead and select static mesh and we can rename this to our item mesh so for our default item mesh we could set this to a one meter cube just like that just so we have a default item mesh and then we're going to click add again we can add a sphere collision we can drag the sphere and drag it onto the default root and click attach just like that and then we can go ahead and click r and scale up our sphere like that and click compile save and go back into our third person example map and we can actually drag in our item master just like that and we'll go ahead and actually scale this down a little bit so in our item master we'll go ahead and scale down and our item mesh can be scaled down like that so compile save that that looks a little bit better so back in here right now what we can do is we can set if we click on our item stats our item info right here but we actually don't want to do this in our master class because of a few reasons first of all if we want to create additional items the issue with this is what we're going to have to do is right click and click duplicate and the problems with duplicating a blueprint is the fact that they're going to be separate different blueprints entirely and the downside to that is when you have like say 100 different items and you scale this all the way up your character is going to have to have custom logic per each item blueprint because there is not one master item blueprint so what this means is if you're casting or trying to communicate with a blueprint you have to do it for each different individual blueprint class so in this case if we added a health potion we're going to have to separately cast to our health potion if we had a sword we have to separately cast the sword to our armor class to our pickups class to whatever blueprint class and whatever items we create we're going to have to cast and basically copy the blueprint nodes over and over for each individual blueprint class and as you can see it's going to be a lot of code and a lot of work so the way to avoid this is by creating a child blueprint and basically what a child blueprint is is if we right click our blueprint master item we're going to see here at the top we can create a child blueprint class and you can see here we've created our bp item master child in this case we can right click and rename this to bp underscore item book and so we can double click our item book here and the first thing you notice is that it's a almost exactly the same as our item master class the only differences between our item master and our item book is the fact that you can see here on the left our components are showing that they are inherited and what this means is it's talking about inheritance and basically when you create a a blueprint class and you create a child the blueprint class that you created the child from is essentially the parent so you have a parent and a child basically our item book here is inheriting everything from the parent class so as you see here in the top right our parent class of our item book is our item master so that is inheritance 101 and basically inheritance allows you to create children of certain blueprints so that you can have the variables components and information in the child blueprints and inherit all of the functions all the variables to create different instances of those blueprints and this is what unreal engine is actually built around and what i mean by that is i can demonstrate this by right click create a new blueprint blueprint class you can see here we have the basic layout of inheritance in unreal engine so first of all we actually have an object and an object is the first parent object in arnold engine so it goes from object is a parent and a child of an object is an actor so an actor is an object that can be placed into the level and then from the actor we have a pawn so a pawn technically is an actor that can be possessed so it can move around either by a controller an ai controller or someone who is playing as the pawn then from the pawn we have a character our character is a type of a pawn that has the ability to walk and move around so you can see the character is inheriting the pawn's ability to be possessed which is inheriting the actor's ability to be placed in a level which is inheriting the object's object class ability to basically exist in the engine so that is essentially the basis of of the unreal engine framework using inheritance and actually object oriented programming and hopefully i didn't confuse you in any way if i did leave a comment down below and hopefully i can explain it better this is how the framework of unreal engine is built around it's built around parent and children classes so in this case we've created a parent and a child all right so what does exactly mean to be a child blueprint class so in this case of our item book we inherit all the different components like i said before in this case we actually cannot delete any of these objects so it means we can't actually delete any of the components here any of the variables or functions but what we can do is we can actually change the variables settings as well as override the variables and functions inside of the children class so for example if i wanted to change the item mesh to a sphere i could do that i could actually move this around as well so i can move stuff around like this if i drag this item book in level you're going to see it's entirely different child class is different from the parents in the case that we've changed the components we moved them around and we changed the mesh so if i undo that basically that means that we can set any of the values here to whatever we want we can set it to whatever we want but we cannot delete it so that is essentially what a child can do right so before we go any further what we want to do is we want to import our project files so go into your content browser here and into our main we're going to add a new folder called resources and in here we're going to first of all make sure you download the project files the link will be in the description below and you're going to have to right click and unzip the project files and in here you're going to have two folders we have the 3d models book hatchet potion then we have the icons the item icons okay so what we want to do is we want to in our content browser you want to create a new folder called resources and in there right click create another folder called item icons in here we can go ahead and select all of our icons and drag them into our item icons then back in our resources we can right click create a new folder call this item meshes and we can go ahead and go to our 3d models item meshes and for our book we can create a new folder for book and drag open it up and drag all this into our book folder you're going to see all these options basically you can just leave this as is and click import all you see this message log no smoothing group here you can ignore this this is just a warning that pops up with every mesh that you import you're going to see the little texture things pop up there saying that it's been imported as normal map and so on that's all fine now we can go ahead and go back into our item meshes and import the second item which is our hatchet so we'll go ahead and create a new folder called hatchet double click that and in our hatchet we can go ahead and select these files and drag and drop it into our content browser leave all the settings as is and click import all okay and then we have our warnings we can just click ok and lastly we're going to go back into our item meshes create a new folder and rename this to potion back in our 3d models we can click in our potion here and drag the models and textures and click import all okay and we can ignore these error issues alright so now we have all of our resources and our content imported into our project what we want to do is set up the textures real quick so for our potion texture we can go ahead and open up the material and drag and drop our texture into our material like so you can select this and delete it and hook this rgb into the base color and then save that as is alright and that should update our potion material just like that then back in our item meshes hatchet we're going to open up the hatchet material here that's the lambert and these models i got these off of sketchfab i didn't create them myself so i linked the sketchfab creators in the description below if you want to check them out but basically you can use these for commercial projects you just have to you just need to credit the original creator okay so in our material here we want to select shift select these textures and drag it over to our material like so and we can select this and delete it and we can drag our diffuse or albedo hook up the rgb to the base color our second map here is our metallic we can hook that up into our metallic and then for our last one we can hook this up into the normal so we can hit save there then lastly we'll set up the book book materials so in the book we can select on this material and we can go ahead and select our shift selector textures and drag this into material and here we can hook up this albedo to the base color hook up our metallic to the metallic or normal map to the normal map and lastly our ambient occlusion ambient occlusion like so okay we can go ahead and save that and now we should have all of our meshes with the materials all set up okay and so now that we have our resources in here we can start creating our different item types so if we go back into our main and into our blueprints we have here this item book we can go ahead and open that up and so for our item book in our bp item book child class we want to set our item mesh to this case the search book so select the book here click r and scale this down a little bit i'm just going to set this to point two and enter point two or two save if we delete this item master and drag our item book maybe we'll scale this up a little bit so we'll scale this up to point point three point three point three all right so now we have our book mesh just like that all right now we want to set the actual item information so one thing you may notice is you don't know exactly where the item info is so if you remember in our master item we don't we can't find the item stat structure so where exactly is this variable it's not exactly in here so what you want to do to get the variable from the item master class is you want to click here to class defaults so we're going to see here in the class defaults over on the right is item stats so if you hit this down arrow you're going to see our item stats structure and all the different variable types so basically any variables that we create inside of our master blueprint class they're going to be inherited to our child blueprint class and those variables are going to be in the class defaults under the default value right here and this is where our variables are going to be stored from our parent class so what we're going to go ahead and do is set our book item stats so in this case we're going to change the item type to a readable we're going to change the item mesh to this book mesh our damage is going to be zero because we're not going to really be using that at all for book item name we can change this to old book and really set it to whatever you want the item icon we want to set it to the project file icons that we've imported so if you search book you want to see here t underscore book texture going to select that and again if you don't have this you want to import the project files textures okay and then we have item text in this case this is our book we're going to put the text that's inside of this book in this little text variable here and obviously if you had a more advanced book with like different pages and stuff you do this entirely different but in this overly simplified example we're just going to set this text variable to some text inside of this book so for example we could just put testing one two three four five test text inside of our book one two three four five just like that okay so this is essentially our item info for our item book class right so that is done we can go ahead and close that we can actually close out of our item master for now and what we want to do is create another child class so right click our item master create a child blueprint and this will be bp underscore item hatchet just like so okay so double click your bp underscore item hatchet and in here we're going to set all of our item info as well as our mesh so we can set our item mesh here to our hatchet static mesh you know it's a little bit small here so we'll click r scale this up and we'll set the value here to something like 3 maybe 3.5 and we can click actually click this browse button and we can drag this into our scene okay it looks a little bit actually no that'll probably be that's probably about the good size you can actually drag this up a little bit if you want it above the center of the blueprint like that okay now we want to set our class defaults item stats or item info so in this case our item type is going to be of the type equippable our mesh is going to be hatchet damage we'll set this to 120 item name we can name this to hatch it then the item icon we can search for hatchet t underscore hatchet right here in our item text we can just leave this blank we're not going to be really using that in this case so we compile save that so now we can go ahead and create our last item so go to our imaster right click create child blueprint class and name this to bp underscore item health potion so in this case our item health potion we can double click this set our item mesh here to health actually it's just called potion and we can scale this up a little bit like one one one maybe move this up a little bit click browse and drag this into our scene okay that looks like a good size so back in here back in our item health potion we can go to our class defaults to set our item stats so in this case it's going to be the type consumable the mesh is going to be potion in this case we want our health potion to restore hp so in this case we're going to be using the damage variable but instead of applying damage what we'll do is we'll apply restore health depending on this variable so we can restore about 30 hp item name we can name this health potion then item icon we can change this to potion t underscore potion and item text we can ignore that okay so now we've set up all three of our item classes which are children of our bp master item so right now if we hit play we can't interact with them we can't do anything with them they're just blueprint actors placing our scene there's no functionality so what we actually want to do is when we overlap this sphere this collision sphere we want to enable our character the ability to pick up the actor and add it to our character's inventory so to do that we want to open up our bp item master and we want to add our functionality and logic inside of our master class the reason why we want to do this is because if we set it up if we set up the base functionality of interacting with the item inside of our master class it will propagate to all of the children classes that way we don't have to repeat our work over for each individual class like i said before so in our item master class we can actually delete these nodes we don't need them in here we want to select our sphere scroll all the way down and we want to add this event on component begin overlap click the add there click on our sphere again and add this event and overlap click the plus button so basically when our character overlaps we want to allow them to pick up the item and when they leave the overlap we want to not allow them to pick up the item so what we can do is off of our other actor here cast to third person character which in this case is our character class and what we want to do is get player controller drag off our return value and type enable input so instead of having this for the target we want to alt disconnect that and hook this up for the player controller for some reason it doesn't work with the target hooked up here you want this particular one to be for the player controller okay and then you want to hook up the execution graph into the enable input right there and then for our end overlap what we want to do is we want to off the other actor cast to third person character you want to off the get player controller disable input and in this case we actually want it to be hooked up to the target then so we can hook this up like so and compile save all right so now what we want to do is add a key on our keyboard to pick up the item so right click add e key scroll up here until you find the e key and really you can use whichever key you want i'm just going to use e and when you press the key you want to get off the other actor cast to third person character hook that up for the pressed all right so when we press e what we want to do is we want to call a function inside our character to pick up the item so we actually haven't created this function yet so what we'll go ahead and do now is we'll go into our third person character to create that function so over in our third person character we can add a custom event so you want to search for a custom event add custom event you want to rename this to pick up item this is a custom event basically these events can be called outside of this class in this case we want to call it in our in our item class but what we want to do is we actually want to add an input for this event so click add new input and what this does is it adds a variable that we can pass from this event into whatever we want so in this case we want to change this from boolean to item structure you want to rename this to item info or item stats whichever works okay and now we should be able to call this event inside of our bp item master class so in there off of our e cast third person character we can drag off of here and call our pickup item event and so for our item info what we want to do is we want to get our item stats and hook it up to the item info all right so now what we are doing is we're adding the item to our character in this case we're calling this function and we're not actually doing anything as of yet but what we want to do after this is we actually want to destroy the actor that way once we add it we can destroy the item okay and we can actually see this work right now if we hit play if i run up to this potion i could click e you can see we've destroyed the actor we've technically called the add event which doesn't do anything but basically we're picking up the item we're going and overlapping the collision which allows us to press e to pick up the item in this case it only destroys it as of now so we have our basic pickup logic now what we will actually want to do is add our third person character pickup item logic once we pick up an item you want to get this item info and you want to add it to our inventory right so right now what we don't have is we don't have an inventory array set up and now is a good time to explain what an array is and in this case what it's going to help us with and in this case how it's going to help us so if we go ahead and create a brand new variable we're going to rename this to inventory array and it's going to be of the type item structure like so and what we want to do is we want to change the variable type here click on this little icon you want to change it from a single type to an array and so a single type is just a single variable and we also have array a set and a map in this video i'm only going to cover arrays and my blueprint for advanced users i will cover the set and the map type so right now we only want to set this to an array so if we hit compile and save you're going to notice down here the default value so essentially what array is a collection of variables in this case if we click this add button you're going to see we have the item info structure so we can actually add multiple items and so an array is essentially a group of variables kind of like a structure but in this case we have an array of structures so hopefully that makes some sense and actually to explain this much better we're going to create another variable and we're going to just name this test array so that i can explain this a little bit better and we're going to change the variable type to just a string so what we want to do is hit compile and save and now we're going to see this is a variable type the type string but instead of being a single type variable we have an array so in our default value we can add multiple strings multiple strings in this array so in this case we could add different strings like maybe we wanted to just add some random text test test one test two test three so basically an array can allow us to add multiple variables kind of like a structure but in this case it can only be one variable type we can add also integers into this array however we can create an integer array we just can't add two different variable types into this specific array demonstrate what an array actually is we can drag our test array string here and we can actually get and we can actually set so first we'll go ahead and demonstrate with a git so off of here we can drag off of here and actually under here under the utilities array we have all of the different array functions so kind of just like the structure instead of breaking the structure info what we can do for an array is we can get the array info so in this case we have the get function which allows us to get from an array at our certain index so basically an array has an index and then the variable the index lets us know where the variable is stored at so in this case our string test is stored at index zero then our string text one is stored at index one so you might have noticed that the array actually starts at zero one two three and the reason behind that is you're going to find in any programming language pretty much any programming language has arrays start at index 0. just keep that as a mental note arrays start at index 0 1 2 3. so when you get from array you want to know the first one is always going to be 0 and the second one is actually going to be 1. so what are actually arrays useful for why is this important why is this relevant so for example what if i was trying to create a multiplayer game or i had a handful of characters on my server let's say i wanted to pick a random a random player name or a random spawn location i want to pick it from an array or in this case a set of data variables in the case of the player name i can pick a random name like john joe smart paulie and ben this is an array of random names basically or in this case strings and what we can do is add a f key so when we press f in our third person character we can get at index zero and off of here we can do a print string and print what we get from our array at index zero so if we hit play and hit f you can see we're getting john because john is the string at index zero so we're getting from our array get at index zero the string which in this case is john so of course you can change the index to index one compile save that and in this case it's going to get joe so hit play hit f we can see we have joe then we can change this to index 2 and we can get smart poly and so on hopefully you understand why arrays might be useful and how to get information from an array so we have the get function from the array we also have the free copy and paste this over we have the add so in this case we can add to our array another name so we could add bob to our array name move down our f key here so when we press f we add bob to our array and the return value is the index of the newly added item so what we can do is we can actually drag this little bit of logic here and print the string right here and hook up the index into our get so what this basically is doing is when we press f we're adding an array element called bob so it'd just be the same exact thing as if i were to click this plus button and add another element called bob in this case i don't i don't want to do that i want to delete that compile save that and so you can see here we press f we're getting our array we're adding to the array a new entry or a new array element and after that we're returning the index of where we added it in this case it's going to be zero one two three four index four then we're going to get at index for the string which in this case is going to be bob so if we hit play we should see bob so by now you know the get function and the add function now there are many more different functions to modify and to to use with arrays and you can see all those functions by dragging off the array clicking under the utilities and under array you see we have add we have clear we can see if it contains a certain item we can find item we can do it for each loop we can do insert and much more so i know this is a little bit brief overview of what arrays are and i will explain hopefully more of this in another video as well as some of the other array functions in another video but in this case this is sufficient enough for you to be aware that arrays exist as well as what arrays are potentially used for so now we can go ahead and delete all this nonsense and we can delete our test array all right now we can resume what we were doing which is we were adding an item to our item array so if you remember correctly when we hit play we press e we're picking up the item and it's calling a function in our character but it's actually not doing anything yet or it's calling this event in our character which is not doing anything yet in this case we want to add the item info to our item array so what we can do is we can actually get our array and we can do add so this is a really simple method of adding our item to our inventory array so right now if we hit play we can hit e and we've essentially picked up an item added these to our inventory array so we can't actually see that happening on our screen but to see that happen in the back end what we can do is we can add a print string and then we can do is we can do the same thing that we showed before where we get from our inventory array at that index we get our item info structure if you remember clearly we have to drag over here and click break item structure to get any of our item information so in this case we can print out our item name into the print string so we can see which items we're adding to our inventory when we pick it up so if we hit play we can hit e you can see we have a health potion we hit e over here we have an old book we hit e over here we picked up a hatchet so you can see we're actually picking up these items we're adding it to our array and then we're getting that item and printing the name to the screen so arrays are very useful for storing data such as variables of different types and structures are very useful for having multiple different variables that way you can store them in arrays so basically these are like the fundamentals of storing data inside your game and unreal engine and when you guys are creating your games you're actually going to be using this a lot when you're creating your game all right so this is great and all but what we actually want to do next is we want to create some user interface so we actually want to display on our character screen the item icon that they picked up so that we can see what exactly we're picking up as well as gave our character the ability to use the items so for example we can actually use our hatchet item and equip it to our character's hand for our book we can display a book text so we can read what's inside of the book for our potion we can restore some health to our character let's go ahead and create our user interface widget so in our main here what we want to do is right click create a new folder and name this widgets and if you don't know what a widget is it's basically the user interface that a character sees so like a health bar minimap buttons anything like that any sort of menu that is basically what a widget is so we'll go ahead and right click under here the very bottom you see user interface we're going to create a widget blueprint and we can name this to w underscore main w meaning widget so we can double click and open this if this is your first time using the widget editor it's pretty simple this is basically your screen your computer monitor screen where you're adding different health bars mini-maps and things like that inside of here then we have all the different items that we can add such as buttons images text box health bars and stuff like that and then from there we have the designer mode and the graph mode so basically we have the designer where we can create what it looks like and the graph where we can create all the blueprint logic for like if we hit a button what to do when we click a button select a certain item when we enter text okay so what we want to do is we want to create our inventory widget basically we'll go ahead and start by searching in our palette here for a horizontal box you'll see horizontal box we'll go ahead and drag this into our screen here and we can go ahead and scale this by dragging these little circles and we can kind of center it like so right so next what we want to add in our horizontal box are the item icons so first of all we're going to go ahead and add a border and then we'll set this to fill on the right over here and on the border we're going to add an image so go ahead and type image here and drag it on top of the border and for our border we're actually going to select on a border here and set the padding to 5 and for our image we want to set the padding to 10 and then we can go ahead and copy select our border copy and paste on our horizontal box two more times so that we have these little item icons just like so okay and so for the style we want to select on the border here we want to change the brush color to this black color right here and we want to change the opacity to 0.5 so it's a bit of transparency and then for the image color we won't select the image here and change the color and opacity and change this to a grayish tint like so and in fact we can just delete our borders and recopy them over so go ahead and copy paste paste okay and the last thing you want to do is you want to take a select our horizontal box and select our anchors anchor it to the bottom center like so that way it'll scale properly so back in our third person character blueprint what we want to do in the event craft is go ahead and initialize our widget and add it to the screen so we'll go ahead and add a event in play and we'll go ahead and get player controller and create widget for the widget class we're going to add our w underscore main and then off of this we're going to add to viewport and then we want to take the return value and we actually want to promote this to a variable and this will be our widget reference so go ahead and drag that out and hook that up and then compile save that so now if we hit play we should be able to see our widget here on the screen we can't actually interact and it doesn't actually do anything yet so let's go ahead and add that functionality so first of all when we pick up an item let's go ahead and add add it to our widget here so back in our widget main in our graph and go ahead and select these and delete these and we want to add a new custom event and we can name this update image and this custom event will have two different inputs so in the details panel here under inputs we're going to add the first one which is integer this will be item index the second one will be a texture [Music] 2d object reference and we'll name this icon for our item icon so basically we're going to when we pick up an item set this image here to the item icon which is in our item info structure so first in our third person character once we add an item we can go ahead and get our widget reference drag on our graph click get and call our custom event which is update image and hook it up like so and then what we can do is for the item index we can select off of here off the ad for the item index and for the icon we can break the item structure here and get the item icon hook it up to the update image there and now we just have to go to our widget main and add that functionality here so what i'm going to do is for our item index i'm going to do a switch on integer and this is essentially the same as a switch on enum but in this case we can add our own user-defined integer numbers so we add a pin you see we have zero one and two and currently if we go to our designer here you can see we have one two three slots technically it starts from zero so zero one two so we have our different item indexes zero one and two so what we wanna do is for zero index zero we want to update image 106. so we can actually go ahead and rename this so it makes a little bit more sense image image01 actually we'll name this image0 rename this image one and rename this one to image two okay that way it matches up with our array so we can go ahead and select image 0 get image 0 and what we want to do is set brush from texture and hook up the 0 to the set brush from texture and for our texture we want to drag into the item icon for the texture and then we want to go ahead and copy the set brush from texture over again and select our image 1 hook that up for the target hook up the one execution pin and hook up the item icon for the texture go ahead and copy paste it one more time and hook up the number index to execution pin as well as our variable image 2 and our item icon okay so now if we go ahead and hit play and press e you're going to see nothing's happening and that's because in our third person character in our inventory array if you had indexes already in here or array elements it's not going to add it so we go ahead and empty that like so just keep it empty inventory array for now and if we hit play we click and click e you see we have the potion icon e we have the book icon and e we have the hatchet icon like so so right now we can't select anything we can only pick up items and you can see it added to our inventory array there as well as our inventory hotbar ui so next let's actually add the ability to select our items so back in our third person character we're going to add two things so when we scroll our mouse we're going to let our character to select certain items based on whether we scroll our mouse up or scroll our mouse down so in our third person character we're going to right click and add a mouse wheel up and we're gonna add a mouse wheel down so when we scroll our mouse wheel up we're going to select or move our cursor to different item icon and then we're going to move when we select our mouse wheel down it's going to move down further down our hotbar so it's going to look like we're cycling back and forth on our hot bar so what we need to add is we actually need to add two different variables so the first one will be called selected index and this will be the type integer and the next one is going to be called max inventory slots and it's going to be of the type integer so in this case for our max inventory slots we can give this a default value of 3 because we only have currently three inventory slots on our widget so we're going to get our selected index here and we're going to get our max inventory slots and we're going to check and see if these are equal to each other and if so we're going to add a branch off of the pressed here so we're going to see if our selected inventory is equal to our max slots if so we don't want to do anything because this is the mouse wheeled up but mouse wheeled down what we want to do is we actually want to do something off of that so in this case what we want to do for false is we want to get the selected index and we're going to increment off the false okay and i'll show you guys what i'm doing here real quick so we can do a print string off of here and we can take the integer into the string so you can see what's happening okay so if i hit play here scroll your mouse wheel up you're going to see it increment all the way up to three so again one two three so basically what this is doing is it's taking our selected index and seeing if it's equal to our max inventory slots of 3 if not we can increment it once and then do it again if we wheel up again we can increment it again all the way up until three okay so this will allow us to cycle through our hot bar one two and three just like that then we obviously want to be able to scroll backwards which is our mouse wheel down so to do that we can get our selected index and check and see if this is equal to zero zero is the first index in our array and we can add a branch off of our pressed here and if so if it's at the bottom we can get our selected index and d increment integer off of the false and we can do a print string to also see what that does take the integer into the string compile save and if we hit play now if we scroll you can see one two three two one zero so you can see we can scroll all the way up one two three all the way down okay and so now what we can do is we can actually allow ourselves to see this happen on our hot bar so when we scroll zero one two we can highlight this border around the items okay so to do that in our w underscore main our widget and our graph we can add another function we can call this add custom event select item function and the only thing we need for our input is integer and it's called item index okay so the same thing what we did here is a we're going to do a switch on end so off of here we can do a switch on integer and we can add three different pins like so and then what we want to do is we want to take the borders and we actually don't have the borders as variables so we go back in our designer here select on the border you're going to see here is a variable and so if you actually check mark this box here it's going to allow us to in the graph use the border as a variable so that will allow us to change the color the opacity and whatnot in the blueprint graph so real quick i'm going to rename this border to order 0 second one to border 1 and the third one here to border 2 and we want to check is variable for all three of those now in our graph here we can take border one and we want to set brush color okay and hook that up from zero to there and we want to change the brush color here to something like yellow so we can see that's been highlighted like so go ahead and copy and paste this over twice and hook up border one border two and then execute execution pin one and execution pin two so now all we have to do is call this custom event inside our third person character so when we do a mouse wheel up we want to get our widget reference and do select item function and hook up the item index into there like so then we can copy this over for our mouse wheel down and hook up the index as well as the execution pin like so so now if we click play we can see we're selecting the items and right now you see there's a bug when we move up and down it actually doesn't deselect an item so it doesn't set the color back to normal it just sets it to yellow so we can update that if we go back into our graph here a very simple fix all we need to do is before we set the brush color to yellow we want to set the previous borders to back to the gray default color so we can go ahead and select all these set brush colors and ctrl c ctrl v to copy for our brush color here we want to set this back to the gray value that we had which was something like this actually we can go back in our designer select our border here and click on a brush color it's full black with a 0.5 opacity so if we go back in our graph select the brush color we can set this to full black with opacity of 0.5 click ok and we can go ahead and ctrl c ctrl v copy and paste these so if you remember we need to set the other borders to this transparent color before setting them to a yellow color so in this case for border zero we want to get border one and two and set them to this color and hook up the x execution pins like so and then for border one here we want to get border two and zero and hook these up like so and for border two we want to get border zero and one and hook these up like so so now if we hit play we can cycle between all three of these you're seeing it's setting it yellow but it's also resetting the color back to normal when we cycle through the different indexes so basically what we've created is a simple mouse wheel up that sets this integer value between a range of zero and three and it adds whenever we mouse fill up and it subtracts every time we now swirl down and it also binds to this function on our widget to change the color of our border here to show that we've either selected the item with this yellow bar or we deselected it and of course we can pick up our item and right now it does not pick up to the item that we have selected so we can go ahead and actually fix that we can also add the ability to use an item at our selected index so for example if i select my hatchet here i click on it we can add an equip or if i click on my health potion we can add a use function where we use the item and restore our health so first off let's go ahead and create our i had item function so right now if you remember we have our pickup item added to the array and all this good stuff right now for this particular tutorial what we want to actually do is we want to instead of adding it to an array right now our character could technically add as many more items as they wanted to there is no current limit on their inventory so what we actually want to do is we want to create a function that will limit and control how many items the player can equip and so on so this is a good time right now to introduce you guys to functions if you haven't already learned about them basically you have the ability to create functions here if you click this plus button so we're going to create a first function called add item so a function basically has inputs and outputs and it allows us to kind of clean up our graph and put all this functionality inside of our function so we can actually take all this control x and in our add item we control v and hook this up like so and what we actually want to do is take our item structure here and drag it onto our ad item and basically what that did is it added a input here for our item structure and of course you could always click this add input or clear like so so right now we're doing the same logic but inside of our function and to call this particular function all we need to do is select our function here drag it onto the graph hook up the execution pin and hook up the item info structure like so now we actually don't want to do the same logic here we want to modify this because for example when we pick up an item we want to pick it up at our selected index so if i had the book selected i wanted to actually swap out the item i have for that hatchet at my selected index if that makes sense so in our add item function we can go ahead and do that advanced logic in here so let's go ahead and delete all this so we can start fresh so what we want to do is first select your inventory array we're going to add three indexes and this is going to allow us to set a cap on how many items we can have in the inventory in this case we only have three different slots and what we want to do is instead of adding to our inventory array we want to set the array element so if we get our right we can go ahead and do what is called a set array element so this function set array element so we can hook this up like so what we want to do here is drag our item info to the item structure right here and we also want to get our selected index into the index like so so right now if i hit play i can add my selected index and right now we are forgetting to also update our user interface so we want to get our widget reference here and call our update image function custom event and for the icon i want to break item info what we can do is only select our item icon here hook that up for the icon and for the item index we can get our selected index and hook that up like so so now if we hit play we can add items at whatever index we have and this will also allow us to replace items so if i hit e here at index 0 it's going to replace that item at that particular index and this is all happening through the set array element so because we have these array elements right here which are technically blank we are setting that particular array element to this item info from our item pickup so hopefully i haven't confused you in any way if so leave a comment down below and hopefully i can explain it further but instead of using the add to our inventory array we're using the set array element function which is a handy tool for giving you more control over your array of values so now up next what we want to do next is you want to actually allow our character to swap out different items so when i pick up an item and swap it out for a different one i want to respawn the item in the world or drop it back into the world so we can do that by going back into our third person character add item function and before we go any further here we actually want to add the last variable in our item structure that i was talking about earlier so back in our content browser item structure double click to open that down here at the bottom we want to add a new variable and for the variable type we're going to search your bp underscore item master set of object reference we want to do a class reference and for the name we want to name this to class ref so what a class reference allows us to do is back in our third person character here we can do the node spawn actor from class and so this will allow us to spawn the actor in this case it'll be whatever item we have we can respawn the item by the type of class that we have set for the reference now what we want to do is basically we want to do some additional logic so before we add an item to our inventory we want to check and see if there is currently an item in that inventory slot so for example if i have an item in here technically we have this empty item but we want to check and see if it has a valid class reference in here if so we can either swap the item or we can add the item so first of all get our inventory array we want to get a copy at our selected index and then we want to break the item structure and we want to expand this and you want to get class reference and c is valid class so basically you want to check and see if this is a valid class and if our inventory array here if you expand the index you can see these are not valid class references here so technically if we were to get our index at this item array here it's going to return a false so we're going to add a branch and hook that up for the condition okay so if it returns false this means that we do not have an item a valid item in that inventory slot so that means there's no valid class reference if so what we want to do is we want to replace the item with this new item that we have so we want to do a spawn actor from class for the true and the class reference will be the class reference from our previous item and then we want to hook up the end here to our set array element so that we can then add the new item to our array one last thing we actually need to hook up the new item structure to this break item structure just like so and of course we need to add a spawn transform so spawn transform we want to tell our character where to spawn the item and to do this what i'm going to do is add a arrow component right here in front of the character so that we can spawn her item in front of the character at all times right in front so go ahead and select your mesh add a component and search for arrow so we can just take this arrow right here and move this forward up rotate it 90 degrees and put it like so right in front of the character and then in our add item function what we want to do is we want to drag our arrow get world location and then off of our spawn transformer we want to right click split the pin structure so this will split the transform which will expose all three vectors and then we want to hook up the world location to our spawn transform location compile save that and we should be able to see the results by hitting play so if we hit e and select our potion here and if we hit e again it's going to swap the items and you're seeing it's not actually spawning the item and that's because we forgot to do one extra step which is to set the valid class reference for each of our item infos so if you go to your blueprints item book for example if we go to our open full blueprint editor class defaults item stats you're going to see here we didn't set any of the class references and for the class references all we need to do is set a reference to the self so in this case bp item book is bp item book and then bp item hatchet you can actually edit it in here class reference here is bp item hatchet like so and then for last item bp item health potion you want to change the class class reference to bp item health potion compile save that so now if we hit play we can hit e here select our health potion and hit e again you can see we're having a little bug there all right and i just realized one mistake was you actually need to take the new item here structure and hook it up to the set array element for the item here or else it won't work so now if you've done this all right we hit play press e select the health potion there and press e you're going to see we've just spawned the item and basically respond someone is working what we need to do is we actually need to set the array element after this by hooking it up like so that way we can set the array element that we pick up and drop it swap it like so so you can see we can switch this to the book to hatch hatchet potion what we can do next is add physics here for items so for you select the bp item master select the item mesh here just click simulate physics this will add for a better better look so i can select this item press e you see it swaps it drops it out of the sky like so okay so e search for a hatchet pick a potion here switch it out for a book pick up the potion here so you can see here we have very basic swap in and out of our items and respawning the item based on the class that is set in each item class as well as in this structure here we can use it to respawn the item actor now what we want to go ahead and do next is based on the item that we have selected we want to actually add the functionality to use that item so if you remember we have this item types enumeration so based on this item type we can do certain logic like equip read and use so what we want to do is we want to add another function now which is called use item so this use item will have one input which is the item info so go ahead and add a new input and name this to item struct and item info like so now we can go back into our event graph and add a left mouse button so when we have our left mouse button we're going to call our use item like so then what we want to do is we want to get our rate our inventory array do a get at our selected inventory index and hook up the item info to our use item function so when we click left mouse button it will get our inventory array get the item at the selected index that we have so in here what we want to do is we want to break item structure and then off of our item type we want to do a switch on item enum and hook up the execution pin like so so now we can do based on our item type we can do consumable function equippable function or readable function in this case we want to create all three of these functions so we'll go ahead and first create our consume item function then our equip item and then our read item so the consume item will have the item structure item info as input and we have the equip item we'll also have the item structure as item info input same with the read item technically you could just duplicate these functions if you wanted to that way you didn't have to add those inputs all right so now that we've created all three of our functions what we can do is drag our consume item equip item and read item function into our use item function so technically you can put different functions inside of a function so it allows you to have a lot of flexibility honestly on where you can call your functions as well as how you can keep your blueprint graph more organized so we can hook up the consumable to the consume clippable to the equip readable to the read we can also hook up the item info for all three of these like so compile save that so in our consume item this will be for our health potion so to see what's happening we can do a break structure and in this case we want to use the damage so if you remember for our health potion bp health potion here we added 30 damage which technically is going to mean 30 hp that is going to restore for our character so what we can do is add a simple print string and technically you could print out the item damage to see how much health that you've regenerated but instead of doing this what we want to do is we want to add a new variable this would be the type float this will be our health okay and we can set our health to a value of 100 hp and now what we can do is we can get our health and set our health actually we want to set our health to maybe 10 that way we can actually restore health back to our character what we want to do is we want to get our health and subtract it by our damage right here and then before we set our health what we want to do is we want to do a clamp float and the min and max maximum will be 100 minimum will be zero hook that up to the set function like that and hook up the execution pin so the reason why we're doing a clamp is we don't want to have our player to be able to go higher than 100 hp like so and then we can also do a print string and hook up the health value into the string so we can see what's going on so now if we hit e we can select the health potion and press left click see we start with zero and technically it's not doing anything because we accidentally did subtract instead of add so instead of that we can do add the damage which is technically the health potion into the value there so hit play we equip that selected press 1 40 70 and then 100. so we can actually bind this to a health bar and that is very easy to do i'll show you how to do that real quick if we go back to our main widgets w underscore main we can add a simple progress bar to our screen scale this up like so we can select our anchor and anchor it to the bottom left and then what we can do is under the progress here you can see the percentage so this percentage drives the progress bar like so what we can do is we can click this bind create a binding and this will create a function right here that will allow us to bind this to a certain variable in this case we want to bind it to our health variable so we can do this by right click get owning player pawn this will basically get our character and then we can do a cast to third person character so this will allow us to get a reference to our character and then from here we can get health and technically you could hook this up but it's not going to work because this is a value from 0 to 100 whereas this is a percentage so we actually want to check take our health value and convert it to a percentage to do that we just multiply the health by zero point zero one and that will convert it to a percentage there and we can hook it up like so so now if we hit play you're going to see our health bar has 10 percent base hp we equip our potion we select it click left click you can see we have 40 70 and 100 hp just like so now one more thing is we can actually spam this health potion over and over and it won't actually remove the health potion from our hot bar so we want to make this a one use only help health potion that way we have to pick up more health potions to restore our health so one way that we could do that is back in our third person character in our consume item we can remove this item array or in this case what we want to do is we want to set get our inventory array set array element at our selected index and basically we're going to set it to nothing that way it's essentially removing the item from our inventory so if we hit play equip that item click on it you see we added 40 hp and you can see nothing is happening uh because it's not allowing it we actually remove the item from our inventory but you can see we still have the item icon on our widget so that means we still need to update our widget icon so to do that do we want to add a new back in the graph here event graph i want to add a custom event called remove image so this will basically set our image back to normal or remove the item icon from our hotbar when we consume the item so here we'll add another input of the type integer and name this item index compile save that then we'll do a switch on integer and add three indexes like we did before and basically for remove image all we want to do is copy paste these set brush from texture from our update image and hook all these up but instead of having a texture reference we can just leave that blank so basically that will remove the item icon like so in this case we only have the used item for our potions so we can go ahead and duplicate these a couple of times and i'm just alt dragging to duplicate this you could also control c control v to copy it but now we have three different health potions we can pick these up consume one pick up another one consume that one pick up the last one consume that one like so so basically that is a very simple consume item of function where when we are pressing our left mouse button we're doing our use item function switch on the item type enumeration and then we're doing a consume item where we're basically adding this to our health and we're updating we're removing the item from our inventory as well as removing the item from our hotbar next up what we want to do is we want to add our equip item function so we want to do here is first break our structure and what we want to do is we want to attach the hatchet mesh to our character's hand so we can do that by adding first a static mesh component and this will be weapon and then we can get our weapon and do an attach component to component the weapon to our mesh component and then we also want to set our weapon mesh so i want to set static mesh to the mesh of our item info right there so we can hook these up like so and right now we don't have a socket name so we need to go ahead and set that up so if we go into our mannequin character mesh sk mannequin we can dock this window at the top and basically a socket allows us to attach certain items to our characters so like a helmet a hat a weapon a sword and this is a skeletal mesh basically a character that has different bones so what you want to do is go ahead and find the hand r right click and add a socket so you see here at hand our socket double click that we're going to rename this to weapon socket and you want to make sure you spell this it's caps lock sensitive so make sure that you remember the name that you put in here so back in our character here we can rename the socket name here to weapon socket then for location you want to snap the target rotation snap the target and snap the target so first we actually need to adjust the socket so if we right click add a preview mesh hatchet you're going to see it's really tiny so we're going to do is actually adjust the scaling and rotation so go ahead and rotate this 90 degrees move this around click r to scale so it's got the basic controls as the normal viewport in our engine and we can do it something like that doesn't have to be perfect okay so now if we hit play we should be able to click on our hatchet and equip it to our character so one thing you might notice is if i try and pick up a potion i still have the hatch equipped to my hand so we can actually fix that by adding a simple decrypt function which will make sure that we remove the hatchet from our hand before spawning the other item so we can go to our add item here move this stuff over like that and get our item type into equals you can see here we have an equal enum so this is very useful so basically on your different item type we can do and check and see if it's equal to the equivalent enumeration then we can click b or add a branch and off of the true we can hook this up so basically if it is equippable and if it is a valid class what we want to do is we want to call a custom event called dequip item or a custom function called dequip item so we'll go ahead and create a new function called d equip item and the only thing that's going to do is we want to get our weapon set static mesh to null basically no reference so back in our ad item what we can do is call this dequip item function hook this up into the true and for our false we just hook it up to the spawn actor like so okay so now if i equip a item here and left click it to equip my hash it i can pick up a potion you see it removes or sets the static mesh in my hand to nothing so again we can go ahead and re-pick this hatchet up re-equip it of course we can pick up a potion and drink it like so so now we have our simple hatchet equipment and potion health potion now all we have to do is add our book item which in this case we want to add text to our screen that we can read so this is a very simple one all we need to do is go to our third person character read item function in this case what we want to do is actually add our widget in our designer we want to add a book widget and there actually is no really book widget what we want to do is add a vertical box and scale it to about this size i want to anchor it to the middle and then in the vertical box we want to add a multi-line text box to our vertical box select that and click fill then we can add some default text here like test one two three four five testing one two three four five and we can expand the style here we want to make the font larger size 20 and compile save that it'll update the text and for our font color we want to actually change the font color foreground here to white so we can actually read what we're doing and then for our multi-line this is make sure it's a variable is checked in our graph what we want to do is add a couple things we want to add custom event called open book and what this will do is we'll add a input of the type text it'll be the book text so what we'll do is we'll get our multi-line editable text box and set text and down here set text hook up our book text like so and then we actually want to make this set visibility to visible and before we do anything we want to go to our designer and go to our multi-line text box and set the visibility to hidden so down at the very bottom we want to just set this to hidden that way we can't see it by default so now if we go back into third person character we can get our widget reference and do open book and for our text we can break the item info and hook up our item text like so so now if we go back to our play you can press e left click and you can see we have our book text now one thing you might notice is we there's no way currently to hide the book so what we could do is if we click again on our book we can make it hide or you can make the escape button make the book text hide whatever you want to do in this case i'm just going to make it so once you click again it will hide the book so this is very simple all we need to do is before we read our item we want to add a boolean and this will be named book is book open question mark so we can go ahead and get is the book open and do a branch so first we're going to check and see is the book open if so we want to hide the book if not we want to open the book so we need to add another function in our w widget main called add custom event this will be called hide book okay and basically what we're doing is we're going to set the visibility or text box here to hidden compile save that and back in alter person character and copy our widget reference over and do the hide book event and actually we want to reverse these so all to click these if the book is not open we want to open it and the book is open we want to hide it and then of course we want to set our is book open to true copy paste is open and set this to false so now if we hit play we can show our book is open and our book is closed very simple so now we have our health potion our book text and our simple hatchet equippable all set up using blueprints structures enumerations and arrays so yeah anyways that is the simple inventory system just a very basic bare bones system teaching you how to use custom enumerations custom structures arrays how to modify information within the array and also kind of how to wrap that around your game using user interface like widgets anyways i hope you guys were able to learn something in this video and i hope i didn't confuse you in any way now i will be making a follow-up tutorial called blueprint for intermediate users where we're going to talk about some more advanced topics such as blueprint interfaces data tables line traces and more so guys stay tuned for that but yeah like i said i hope you guys enjoyed the video if you like this video make sure you hit the like button and subscribe for more future tutorials and as always i'll see you guys in the next one
Info
Channel: Smart Poly
Views: 126,212
Rating: undefined out of 5
Keywords:
Id: x5KlU7Q4MzY
Channel Id: undefined
Length: 125min 50sec (7550 seconds)
Published: Thu Jul 29 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.