Inventory tutorial (Part 1) - Create and add items - Unreal Engine 5 [Blueprints]

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone in this series of videos we'll see how to create an inventory system in un n 5 using brou so for this video I created a folder called inventory right now the folder is empty this is where I will store everything related to the inventory logic I'm going to double click on it and open it and in there the first thing I'm going to do is create the actual inventory component so I'm going to right click choose blueprint class and I'm going to choose an actor component I will call that bpc for blueprint component uncore inventory this component will be attached to the main character at the moment we have nothing in there and what I'm going to do is go into the blueprint for the third person character going to open that and going to add a component going to look for in inventory and see that bpc inventory pops up choose that and won't change the name just going to leave that as bpc inventory so now our character has an inventory but the inventory is empty and there's nothing yet we also do not have any items to pick up and put in this inventory so I'm going to go back into my inventory folder and in then I'm going to create the logic to create as many objects as we want in the game that we can pick up and add into this inventory so to create objects I'm going to right click choose blueprint and in this case I'm going to create a specific type of blueprints I'm going to choose the structure blueprint or struct I'm going to call that struct item this blueprint here when you open it you can see that you have by default one variable and you have this button to add as many variables as you want this structure will be the base of all the items in the game this is where we're going to Define every parameters and every variable related to objects so for example I'm going to change the first one to name and I'm going to change the type to string so now every object that I will create using this pattern this structure will have one variable called name this is definitely not enough for any objects in the game so let's add a description too which ALS will be a string and let's add another viable like let's say bullan called is weapon to know if the object we are picking up and we be using is a weapon and from there you can create as many variables as you want depending on the needs of your game a good thing you can do is add a texture so I'm going to name that image choose a texture texture 2D and this is something you can use to have for example an icon in the UI of the inventory so right now I'm going to stop here leave those four variables and I'm going to save the structural item as I just mentioned this truck will be the base of all the items in our game so we have this Base Class this base structure but we don't have any items yet so to create them now it's going to be very simple if you do right click and choose miscellus you're going to look for a data table you can see that you can choose a row structure here you can see there's a lot of things available none of them really matters to us except the one at the bottom called struct item which is the exact same name of the structure we just created so I'm going to choose that and press okay going to rename this new object DT so oops rename DT and in that case I want to create a source so going to call that DT so we can see that once I open that the T table seems to be empty this is because we need to click on ADD at the very top which will add a new row to the data table the moment I do that we can see a neuro with all the variables which is defined in a structure item so you can see image if it's a weapon name description so in this case this subject will just be called sword description where it's a it's a sword so just it's a sword and yes this is a weapon I'm not going to choose the image because I don't have any Sprites at the moment but you can just look at that later on and we'll see in a later video how to display this inventory into a UI to see what objects we have and finally one last thing I like to do is that by default if I make everything slightly bigger we can see that this is all the variables we have but the row name is simply called new row by default so I'm just going to right click and press rename and just call that item so I'm going to save that and this is all we need to do for the actual structure of the item so I can close this can call close the struct item too and I'm going to go into the bpc inventory that we created at the beginning of this video going to delete all the functions going to save and now I'm going to create a new variable in here which I will call inventory and by default we have a ban type that's not what we're looking for what we want is a struct item once again because this inventory varable will store all the objects that we are creating in the game all the objects we can collect and add to the inventory or remove from the inventory so I'm going to click on struct item if I simply leave everything at that our inventory is going to be able to only hold one item so what I want to do is change the type the variable type from single to aray so now the inventory can have multiple objects in it not just one object multiple ones and an inventory system is pretty much an array of whatever objects exist in the game so we just need this one variable called inventory make sure this is an array of the type of things we want to store in the inventory which in our case is a bunch ofu items I'm going to compile everything seems fine so now that we have an inventory we also can have objects we need a way to add those objects into the inventory so I'm going to create a functions here and I'm going to call that add to inventory so this add to inventory function where what we want to do is get our inventory and we want to add things to it so from the inventory pin I'm going to drag it and look for add in this case the add I want is the add from the array utilities section I don't want to use the add operator because this is not doing and I'm just going to click on ADD here we can see that we can connect that to the function we can add anything to the inventory but we need to add an item here and we don't we have an item yet this is because in the inputs of the add to inventory function I need to create a new input which I would call an item we want to add one item to the inventory and because the item follows the same structures we've been creating going to look for struct item and I can connect that into this ad function so what we're doing is very simple is that we have a function to add an object to the inventory this object needs to fit the pattern of the inventory which is a structure item which we just created and this is it this is pretty much all we need to do to add any objects to the inventory so I can save and compile everything seems to be working fine so now that we have our logic to add an item to an inventory we need to find an actual item in the game and we need to be able to interact with this object and pick up the object to put it into the inventory we have the logic to have the actual inventory but we need this pickup logic too in my case I have a BP interactable class here where I implemented an interact interface I won't dive too much in this video on how to do that however I have another video that explains how to create an interface to have an interaction with objects in a engine so I'm going to go from there there and I will put a link to this video in the description in this case I'm going to open this beffy interactable I have and I have this interact interface that's already implemented from there what I'm going to do is I want to cast this object to the third person character and to cast I need an object here which is get controller if I combine we can see this is not get controller it's get player character and if I compile this should be working fine so I have my event track that's linked to the cast to to the third person character and as the object we have the get player character from there as the BP third person character I want to get the inventory component created so get bpc inventory and from this I want to use the function add to inventory and I want to connect the cast into this function at to inventory if I combine everything seems fine but we're not any we're not adding any item yet we can see that the PIN for Whatever item we want to add is not connected to anything so in this case for this BP interactable is I'm going to create a new variable called object to loot you can find a better name than that but hopefully this is clear enough for the purpose of this tutorial and this I won't look for a structural item this time I will look for a data table so if I look for data table here we go data table object reference so I'm going to get this data table but we can see that it won't connect to the item yet this is because we need a function from the data table so if I drag the pin from this object toot variable and get and look for get row we can see that we have a utilities function called get T table row and this is what we're going to want so I'm going to move the pins from before drag that a bit on the right it is connect the cast into this geta table row in this case I'm looking for a specific data table which is the object to loot we want and I'm going to change the row name to item and once the row is found I get row found and I connect that into the add to inventory and once we have something the AR row will be connected to the item so to explain a bit more on what's Happening Here we created a structureal item and from there we can create as many data tables as we want that would represent every object that we can store into the inventory of our game in that case we have one object so far called data table sword or DT sword it has multiple variables and it is stored as a data table what we're doing here when we are interacting with an object is that we have an interaction we can be able to pick up the object once this happens we need to cast that to the third person character so we can access the inventory component we created at the beginning once we access this inventory component we can access the function we called add to inventory which allows us to add an item to the inventory however we need to know what item we are adding to do that we are creating a variable called object to loot which will be a data table which will store the values of whatever objects we want to have and to get from a data table to an actual item to add to the inventory we just need to use this function get data table row which will simply tell us all the variables of this data table and convert that into the structural item so we can add that directly into the inventory and the last touch that will make everything make more sense now is I need to change this object to viable from private to public by simply clicking here on the I button going to compile and Save my BP interactable I will drag this object into the world and once this is into the world we can see that we have this this object to viable here that is by default empty and once I click here I can choose different data tables so in that case we only have one called DT sword but let's say I want to create a new one so I'm going to create go into the inventory contrl C control V on data sword and I'm just going to rename that to let's say data Shield just going to open that very quickly and change the text to shield and text to is Shield so going to leave that as a weapon even though it's not really true and now if I click back into my BP interact symbols in my scene into object to loot can see that we have a new object that a shield or another a soul here so here this one is going to be sword and this other one here is going to be Shield so for every object that you can collect in the world you will be able to access the object to or in other words all the information regarding this subject directly into your interactable and to make sure everything is fine in the inventory the bpc inventory blueprint I will simply add a print string and in here going to get a break structureal item we can see all the values here let let say name so by doing that I'm getting all the variables of the social item we're going to pick up and add to the inventory and I'm just going to get the name one to print to make sure that every time we add to the inventory uh it's working actually just change the code a bit to make sure that we have a text that makes more sense so I'm appending two strings together one saying that I added the following items to the inventory and then it will add the name of whatever items we're picking up I'm going to save now that I'm in play mode I can see that I want to come to those objects I have the pickup text for the interaction logic if I press my e button can see that we added to the inventory the following item shield and if I go here it's going to say sword added item to the inventory sold so this is it for this video we saw how to create items how to add them to an inventory but in the next video we'll see how to update this inventory when you have multiple items and later on we also see how to display an inventory UI to see what is actually currently in our inventory so this is it for this video and I will see you in the next one
Info
Channel: Morrigan
Views: 278
Rating: undefined out of 5
Keywords: unreal engine, unreal engine 5, tutorial, ue, ue5, unreal tutorial, unreal engine tutorial, unreal engine 5 tutorial, ue tutorial, ue5 tutorial, inventory, inventory system, inventory tutorial, video game, game dev, video game development, unreal development, inventory unreal engine, inventory unreal engine 5, inventory tutorial unreal, inventory system tutorial, inventory system tutorial unreal engine 5
Id: 8736rxVHV6Y
Channel Id: undefined
Length: 16min 7sec (967 seconds)
Published: Mon Jul 01 2024
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.