Unreal Engine 5 Tutorial - Inventory System Part 1: Inventory Component

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] hi everyone and welcome back to the new and improved inventory system series that has been rebooted because I just wasn't happy with the way the last one was going uh there was too few too many bugs and uh yeah so rather than try and fix it and make it work with the bugs it had I've actually read it from scratch and so the whole project is now available to Gold patrons over on patreon.com forward slash Ryan Ailey plus many of the first few episodes are up there too so in this first episode we'll be going over the setup for our inventory system looking at the component its various functions and variables it will need as well as the structural need for the item itself so let's get started the first thing to note about inventory systems is that we need to first or set up whether or not we're going to have an ordered list on Arnold list now what we'll be doing for this one is an ordered list meaning that each slot is going to be unique to itself and that each one have a unique ID meaning I can then transfer slots move them around organize them as I Wish by dragging and dropping them around my scene so we're going to go ahead and set up the first of all the inventory component which will then be able to apply to both the player and other objects to create containers let's start off by creating that component I'm going to go into our content browser down here and I can last new folder to keep all of this in and inside here we're going to add a new blueprint class go to act component down here and we're going to call this one inventory system the inventory system is a actor component which means we can attach it to other actors to add extra functionality and variables that we can use freely throughout the game so we're going to open this up and I usually like to start with the core Basics that I'm going to need in order for our inventory to work or any sort system to work so we'll set up some basic events and functions to handle this stuff first of all let's clear this default stuff we don't want this and instead let's set up a couple of functions so the first function I'm going to add in here is going to be an add to inventory quite obviously we need a function here to enable us to add our content to our way of storing the slots next we also need over move from inventory and then we're going to need some variables and the first variable we're going to have is so inventory size and we want to store this as an integer that way we have a whole number indicating how many slots we're going to have in our inventory here now alongside this we're going to need our content now that is going to be the meat and bones of all this and this content is going to be an array of structs now structs oh waves are storing loads of variables together in this case we'll be storing two in an ordered fashion so let's go ahead and create the struct for this we're going to go into our blueprint menu here I'm going to create a new structure the key definition for this is that you're going to use F and then you type in the name of your struct so I'm going to do slot struct and let's open it up now I did briefly mention that this will involve two types of variables the first one would be in ID name which would be the item to Item ID and that'd be a name and the other one will be a quantity would be a integer sorry I can then go back to my inventory system and in here we're going to create our variable but our content which I'm going to call this content and inner available type I'm going to search for our F slot struct to find it there and this is just a singular one so to make it a store multiple things we need to make this an array so click a little icon next to available type and change this to an array and there we go so to make this work for multiplayer there's a couple of things we're going to set up here too the first thing we need to do is make sure this whole component this whole system is going to be replicated I'm going to go to class defaults and you go down to component replicates and turn that on we are then also going to replicate our content array so click on content array and go over to the right hand side you'll see replication change that to replicated now when you do change this replicated what that does mean is that if the server changes the content of this inventory component it will replicate it to all the clients as well so we will be setting up some further functions to enable this but just know that for now it's replicated only the server can change this content quite important that you know click save and then we'll go back to our player character and we're going to add it to our player character in the component list here there you go now over here on the right hand side you'll see inventory size as default into zero I'm going to change that to 16. and content here we're going to leave blank but if you did want the player to start with some content you can indicate that here just fine now in terms of the actual content the actual items that you'll be picking up and spawning and so forth uh you'll need to make a data table for this and for this to work we need to have some structure about what are the items that we need in our data table so in that inventory it's a folder here we're going to create another struct it's going to be F item worked and this is going to be a structure that contains all the details of the individual items so notably the first thing we'll want to know is their name so what are they 'll be a text field make another one and this will be a description we would then probably have a thumbnail so we'll need a thumbnail to be able to see it inside of our drag and drop interface so I'm going to go in here and set that to a texture 2D okay and hit save and that okay and then we're going to add in here the item class that we want our item to be so when we the reason why we need this is if we then make it so we drop the item we know what item we actually are dropping inside the environment as an actual thing so we're going to go in here and set that to an actor and class reference so you just hover over it and go over to class if it's here and you choose a class if it's because if it doesn't exist yet in the world you want to use a class reference if there's a particular one in the world that already does exist you want to use an object reference and the last item we're going to add in here for us at least is going to be this stack size it's a bit integer now the stack size would be how many items of that same class the same type can be stacked into one slot so before it has to go into a new slot okay so if you picked up 10 apples you'll do I think but you've only got five five stack size you can get two slots filled up with apples there okay um but that's all we need here for now but you could also add more stuff onto this so you could have things extra details so like if you're doing like a merchant system you can include things like buying and sell values you can also include things like their weight if you're doing incumbent system whatever you may wish okay for us that'll do there and we'll just close that there and I'm going to create our empty data table we just right click inside of your contact browser go to miscellaneous data table and then choose your F item struct okay request one item data and it's in here where you can fill out the information about each item which we'll do later on in another episode there you go we've got the start of our inventory system ready to go in the next episode we're going to work on our interaction system allowing our player to interact with items around the world in order to pick them up or put them into chests so you watch it next upload right now over on patreon.com forward slash Ryan lady let me catch all my videos early before everyone else from just one dollar a month massive thank you to all my patrons and user members for the continue support thanks for watching make sure you're subscribed and I'll see you next time bye everyone [Music] thank you [Music]
Info
Channel: Ryan Laley
Views: 87,846
Rating: undefined out of 5
Keywords:
Id: vHT4MhmwacE
Channel Id: undefined
Length: 9min 43sec (583 seconds)
Published: Mon Oct 10 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.