Unreal Engine 4 - Inventory System Tutorial (Free Download)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] before we start this video let me quickly explain how it was produced and why it took so long to produce having never created an inventory system before i first had to learn how to produce one so i started watching youtube tutorials two times speed for good measure the hard part wasn't learning how to create an inventory system the hard part was trying to reduce the huge amounts of information you need to know into an easy to follow simple and straight to the point tutorial so instead of doing the easy option and copying a pre-existing inventory system i said pocket i'm going to create my own inventory system from scratch which cuts out anything unnecessary so my viewers can get straight to the good stuff and now i'm proud to present a completely free inventory system blueprinted in what i believe to be the simplest way possible features include picking up and dropping items stacking items and item descriptions this comes with a customizable ui along with the photoshop files allowing you to easily create more ui items and finally free consumables which can easily be blueprinted to fit your game's needs from me to you hope you guys enjoy it and thank you so much for supporting my channel what's up guys and welcome to another video the link to the download is in the description but before you do that i've actually got two options for you to consider the first is to download the entire inventory system in its entirety and try and figure it out by flicking through the video i've actually left some comments on the wall to try and help you guys figure out but i wouldn't recommend this option the eventual system is pretty complex even though i've simplified it down as much as possible so if you're feeling brave go for it but i wouldn't recommend it the second option is to join me in this tutorial and we'll go through it step by step and you'll get a real understanding for it i personally believe to learn unreal you have to know everything that's going on you have to know how something connects with something how something passes information to another thing and when you all know when you know that then you can scrap all the tutorials and you can begin on your own adventures of making whatever you want so i'd suggest following this option but if you want to just download it feel free i'm giving it to you guys whatever you guys want is good so for those of you following me on the tutorial nice one i need you guys to click the first link in the description it's just something to start with so we don't spend too long wasting time on things which don't really matter and those of you who just want to download the inventory system thank you for watching the video this far i really do appreciate it you guys need to click the second link in the description and that will download the whole lot for you so guys when you've downloaded the tutorial package you will have a project which looks something like this all i need you to do is take the my great folder right click migrate and click ok and migrate all of that to your other your main project content folder so guys when you've migrated it you should have a lovely folder called migrate here just sitting in your content browser and for anyone following the tutorial series i just thought it was worth mentioning that i've just built another room coming off all our other rooms okay let's get into this now so let me quickly give you a rundown of what i've given you guys so far so in our consumables we have all the different potions and all these are just a static mesh with a severe collision box around them they've got two we've got an event tick which just makes them rotate and they've got a used item function which i just left in there materials and textures pretty self-explanatory these are just the materials used for the different uh bottles and then the textures so these these icons here i actually got these off a website i'll leave a link in the description they're all free for use and i made the inventory system background and this blank is just a blank image with nothing in just for our widgets to hold on to until we fill it with an icon so now for the ui the widgets so this is where all the blueprints are going to be happening obviously i've deleted all the blueprints for now but i just wanted to give you the initial widget to save some time so let me just quickly explain what's going on here so this is an inventory slot this is where one of our items are going to sit all we've got here is basically a canvas panel size box overlay this is just to hold things in the right place then we've got an image this has got the blank image texture so this is nothing at the moment and this is where we're going to put our icon image then we've got the quantity which is going to be how many of the item we have with this is just their text then we've got a button this is going to be when we click on the button we're going to be able to use and drop the items etc then we've got the drop and use hud here we've actually brought in the the other widget we've made here this is where this will sit when we bring it up and the description this is just the text render where our description of the item is going to go the used drop hud is just two buttons with a text on top and for the inventory this looks really complex but it's really not all it is is an image with the texture that i made here this is the inventory background texture we've just thrown that onto a image slot put it in a canvas panel so we can move the cameras panel around and then the big canvas panel which will just lock it into the center and then we've just added lots of the inventory slot widgets as i said you can add widgets to other widgets so we've just got all our inventory slots here we've only got up to six so if you want to add any more you can either right click and duplicate this or you can just bring in inventory slot widget and you pull it into your canvas panel in terms of functionality all we've got is a few uh custom custom functions which i which are left in here and all i did was make me when when we construct this widget we're going to make an array and we're going to add all of our inventory slots to this array so if you want to add another inventory slot you just click add pin make another inventory slot control to bring it in then just connect it in like that this just means we can call upon each one of those inventory slots and go through them when we need to okay so the first thing we're going to do is open up our character blueprint what we want to do here is just bring in our inventory so we're going to right click begin play if it's already got something that's no problem what we're going to do is create widget so what we want to do is create our inventory widget make sure you do the inventory not the inventory slot then we're just going to promote this to a variable call it inventory widget okay so now we've actually created our widget now we just need to call it open it and close it when we press i or a key press so i'm going to use i for i for inventory so if you just type in i maybe i key then bring in your inventory widget we just made bring in a flip flop so this will be what this will do is when we press this once it'll do a if we press this again it'll then do b pretty simple then off our inventory widget we're just going to add to viewport then we can drag off our inventory and remove from parent so this is going to add and take it away from our screen when we press i but there's actually we actually want to make it so our mouse cursor is shown and the when we move our mouse the camera of our character doesn't go all over the place so we're going to get player controller and then we're going to set your mouse cursor to true you know duplicate this with control and w plug this into the player controller then we're going to uncheck it so now to stop the camera moving around when we move our mouse we actually need to set the the game mode so if you drag off your player controller set input mode game and ui widget to focus is going to be our inventory widget control and drag that in so now when we close the inventory we want our mouse to be able to control the camera again and not to be locked into the screen so we're going to drag off this and set input mode game only now if we compile and save this we should have our menu system opening and closing here is our dude press i opens our mouse locks and then if we close it our mouse goes back to the camera and the inventory system closes so now we're going to implement something so we can interact with our consumables so what we can actually do is make a blueprint interface so if you right click under blueprint create a blueprint interface a blueprint interface basically holds certain functions and these can be applied to lots of different blueprints so we're just going to call this interact because this is going to be our way of interacting so we're going to double click to open it up and we're just going to make a function and we're just going to call this interact and that's all we're going to do here so what i need you to do is open up each one of your consumables then under class settings if you click this on the right under interfaces you can add your interact interface as you can see i've already done it so it's not showing up but if you just click add find your interact interface or whatever you called it and bring it in now if you press compile and you right click and type in interact whoops so i know it's quite hard to get your head around but just think of this blueprint interface as a way of calling these different events from all these different consumables without casting to all of them so we don't need to cast the health potion cast the mana potion we can just cast them using this blueprint interface and it's just a more simpler and tidier way of doing things okay so now go back onto your character blueprint now we're going to be able to interact with these different consumables because they've got this event interface so what we're going to do is i'm going to type in e key because i want this to be my key where i'll interact with an object yours can be anything you want and we're going to right click get overlapping actors type in actor and then we're going to pull off this array and do for each sleeve okay so what this getting overlapping actors does is basically it checks within all the blueprints because blueprints are actors if you are overlapping them and because on these consumables that we made or that i gave to you they've got this sphere this will detect if we're overlapping them so back on our crash when we press e we're going to check what actors we're overlapping then we're going to pull off this and does implement interface then we're going to type in the interface here then we're going to do a branch loop this and then we're going to pull off for each loop and we're going to interact i actually did a wrong node here i meant to write for each loop with break so just bring that in instead bring that array into there bring that into there and then bring that into there when we find a consumable we can interact with we no longer want to start looking to keep looking for anything to interact with okay let me explain quickly what this is doing so when we press our desired hotkey we're looking for all the actors that we're overlapping if they have the interface interact in their class settings which our consumables now do because we just set that up if that's true we're going to fire off the message interact which will fire this message this message this message depending which one we're overactive we're overlapping then when we when we fired one off we're gonna stop doing this so we only interact with one so now we can test this out by bringing our consumables into the level and i'm just going to pull off this and destroy actor press e gets destroyed gets destroyed that's destroyed so that's all working great okay so now what we're going to do is we're going to give all these items some characteristics we're going to give them are they consumable are they stackable so we're going to go back onto our content browser we're going to right click create blueprint and create a structure and a structure is basically basically kind of like a database it can hold different variables that you set so we're just going to call this item info structure and double click to open this up so this is what a structure looks like looks a bit scary if you haven't seen one before but it's very simple so the first thing we're going to do we've already got a variable here so we're just going to call this name that's going to be the name of our variable and we're going to make it a string then we're going to add a new variable call this icon then under the variable type we're going to call it texture 2d if you're wondering what i'm why i keep looking over here it's because i'll keep on looking at my already built inventory system so i know what to do then we're going to create a new variable is it stackable and this is going to be a boolean new variable item class what type of item is it going to be and for this we're just going to type in our health potion so it's basically just going to be an actor and make sure you do class reference then new variable description this is going to be what's going to be describing our item and that's going to be a string so for the default values this is what they're going to be as default the and we're going to click stackable to true and we're just going to type none in here then we're just going to save then close this down then go into your first consumable now we're going to create a variable and bring in this structure so gonna new variable type in item info and under variable type type in item info structure so now we've brought in this structure if you click compile pull the arrow down we can now start giving this item some attributes so name health potion i icon is going to be the health potion icon stackable we want it to be stackable and then health potion description heals 50 plus points just go on to your consumables if you right click duplicate your health potion call this manna potion 2 duplicate health potion again call this stamina potion two open up your mana potion two just change the static mesh from health to mana compile stamina potion two change it from health to stamina as the color so now for the mana potion make sure you change this to mana potion and the mana potion icon [Music] same for the stamina potion so we've got our consumables with all their data what we need to do now is pass that information over to the inventory widget so what we're going to do is go into our content browser under ui under inventory and in the graph you can see there's already some events here so this is going to add the item to the inventory but what we need to do now is add an input to this so this variable can be passed from our consumables the item info can be passed from our consumables to our inventory so we're going to add an input we're going to call this the item info then under variable type we're going to bring in our item info structure so now we've got a custom event which we can pass the information to now we need to pass the information so back on to our consumables we're actually creating the inventory widget in our character under event begin play we create the inventory widget and we call it inventory widget as a variable so what we need to do is get player character cast to our character mine's called crash car then we can pull off this and we can actually get that widget that we made now we've got the reference to the to the widget in our inventory we can call the add to inventory function add to inventory function now we can bring in our info that we've got in our each one of our consumables so this has all the data about our consumables and we can pass that to our inventory system using this function so now our inventory system when we when we overlap and interact with this consumable we're passing this information over to the inventory and it's coming out here so now back on our health potion consumable if we copy all this for our other potions stamina potion and mana potion depending which one we interact with as all of them have different information stored we're going to pass different information over to the inventory system and the inventory system can then use that so now at the end of our consumables we just want to destroy the actor so we pass the information over to the inventory system then we destroy the actor so i'm just pasting this over to our mana and stamina potion like so okay so we have all the information being passed over to our inventory widget which will then apply it to our inventory slot so first we need to do a bit of work on our inventory slot under ui inventory slot okay so the first thing we're going to do is we're just going to create our use and drop item widget we won't use this till later but it's good to get this out of the way create widget then use drop hud so this will be when we click on our click on our item then the use drop item widget will appear and then we're going to just promote this to a variable call this use drop heard widget okay that's stored as a variable cool so what we'll be doing is we'll be passing the item information to the inventory here and then we'll pass this to an available slot after we've blueprinted it so we're going to add an input and this is going to be our item info that we pass and it's going to be the struct again item info structure then we'll promote this to a variable just so we don't have to keep referencing this bit and this will just be the item info now let's set some things in our widget so we can set the image we can set the quantity and description etc so first we're going to make a variable called current quantity and this is going to be an integer this will be storing our quantities pull this in with ctrl drag drag then we're going to plus one to it because when we add an item to this slot we're going to be plusing one to it if there's already a quantity of one then it will add one so it'll appear as two then we're gonna set uh alt drag in our current quantity and set our new current quantity as plus one then we're going to bring in our image this will be the icon image by default it's set to blank yep it's set to blank here so nothing's appearing then we're going to set brush from texture get our item info so the item input that was passed to us we're going to split this open and in goes the texture that we've got from the item then we're going to set the quantity so bring in our quantity this is just a text variable and we're going to set text and this will be our current quantity we made although this is an in if you plug it into the text it will get converted to a text like so plug that together then we're going to do the description so bring in our description text we're going to set text again and what we'd usually do is just pull in the description here but we actually want it to say description in front of it so we're going to append this is how you combine two strings together so this will be our start description space plug in our description here and that will convert it to a string so now when we get an item added to the slot we're going to create a variable with all the details of the item we're going to plus one to our current quantity then we're going to set the texture to whatever the icon texture was from our item that we picked up then we're going to set the quantity to plus one which we already did over here and then we're going to set the description to whatever the description is but we're going to add description bracket bracket in front of it and then we just need to make one more variable called filled question mark and this is going to be a boolean so when we set an item to this slot it is going to be built so for for these widgets the inventory system all this is gonna do is find an available slot in the inventory slots here by cycling through the array finding a free one and then we're gonna send the information over to a free slot or if we've already got a slot there we're going to plus one to the quantity in the inventory slot this is where we'll be doing all the functionality of that slot so if you want to use the item if you want to drop the item if you want to show or hide the drop menu it will all be done in the inventory slot so inventory finding a free slot inventory slot or the functionality of the slot so before we add any functionality to our inventory slot let's just do the inventory so we can assign slots for all the different items so the first thing we want to do when we pick up an item is check if there's an item that's already in the inventory which is the same so we can just plus one to the quantity so in the top left i've actually already made a function for this procedure and we're going to add an input with the information data of the item so under input call this item info and it's already got if it doesn't type in item info structure so it's going to be our structure so this is going to be the details of our item so we're going to bring in our inventory slot array so this is just all the inventory slots so we're going to cycle through them to see if any of them already have an item in which is the same then we're going to do for each loop with break then connect this up and add a branch with holding b and click so all our inventory slots which have an item in it will actually have the item information stored in it as the item info variable we made so what we can do is we can get that item info get item info we can split it apart then we can get the item that we've just picked up that information and break it apart then if the item we picked up's name is the same as any of the names in the inventory slot so if there's a health potion in one of these inventory slots if the item we just picked up also has the name health potion then we can just add a quantity so we'll do an equal sign so if they're the same plug that into the branch and if the item we've just picked up is stackable because even if they have the same name if they're not stackable we want them to be in two different slots if they're stackable we're then going to call the function in our inventory slot add item so pull off this set item to slot and then the item we're going to be bringing in is going to be the item we've just picked up but if the item we picked up doesn't have the same name as any of our items in our inventory we then want to call the check available slot variable function which will check if there's an available slot and then assign it so i've completed we want to then check available slot but then there's a problem with this because if we set the item to the slot when this eventually completes we're then going to check for an available slot even though we've already assigned the item so we only need to we only want to do this if we haven't found an item where we can increase the quantity so what we can do is create a variable call it item set i know this may seem confusing for now but it will all make sense when it's all completed so we're going to set this to true so we have found an item and then we're going to stop this from looping anymore just going to add a re routes node here by double clicking and then we only want to check available slot if we haven't found an item so bringing this in with control and drag bringing a branch if the item has been set we don't want to do anything but if it hasn't we want to find an available slot for the item we then just need to set this item set back to false for if for when we pick up another item we can go through the same process again so we're going gonna alt drag this in and set this back to false so let's run it down real quick we're going through each inventory slot does any of the inventory slots have an item with the name which is the same name that we just picked up if it does is it stackable if it is we're going to add one to the quantity to the slot then we're going to stop the array from happening set the item set to true because we found an item and then it's just going to come off here once it's completed if we have found an item we're just going to set it to false and do nothing if we haven't found a slot with the same name we can then check for available slot if all these come off false it's just going to keep on cycling through this until all the inventory slots are over then it's going to complete and do that so now we've done this we can go back into our event graph and do the check available slot so the first thing we're going to do is bring in our function check item already exists and then we're going to plug that in like so so we're checking if the item already exists if it doesn't we're then going to check for an available slot which we're going to blueprint right now so now we're going to bring in our inventory slots again before each loop would break so we're going to cycle through all of them and find the first one which isn't filled filled is the variable we made in our inventory slot when an item is applied to it we're setting fill to true so then if it is filled it's going to ignore that slot and move on to the next one so if it's not filled we're going to set item in the inventory slot select item 2 slot and the item we're going to set is the one we've just picked up then we just want to break this to stop it looping around [Music] so it only adds one item to the slot so that's us pretty much done with the inventory already now we just need to do all the functionality in the inventory slot so now if we bring a load of items into our level we can now pick them up so if you press i press e we've noticed we picked up a health potion you don't actually have to have the inventory up it's just easier to display if i press e it picks up as the mana potion doesn't have the same name as the health potion it's moved to the next available slot this is a stamina potion and now we're picking up another health potion as it does have the same name all we're doing is adding one to the quantity so it's already looking really cool now we just need to add the functionality of trump using the item dropping the item and yeah so one little thing i've just noticed when testing that out is that when you first pick up an item it won't actually work until you open and close your inventory so what we need to do is go on to our third person character when we have our inventory we just want to add it to viewport and then straight after that we want to remove from viewport remove from parent so now it will open and close it quickly so it exists and then our items can start going into our inventory without us having to open and close it first so guys i'm actually going to split this video into two parts i've been told by numerous subscribers that they prefer it when it's short and sweet tutorials instead of long ones so i'm splitting it up but in the next episode which will be released straight away uh we're going to be doing the functionality of the items using dropping using the items etc so thank you guys for watching stay tuned for part you
Info
Channel: Beardgames
Views: 91,779
Rating: undefined out of 5
Keywords: ue4 tutorial, ue4, Inventory System, Looting, Picking Up Items, Epic Games, Unreal Engine 4, Unreal Engine 5, Tutorial, UE5, UE4, unreal engine, Beard games, Beardgames, unreal engine 4, unreal engine 5, epic games, ue5, gamedev, unreal engine 2020, game dev, unreal engine tutorial, unreal, game developer, indie gamedev, unreal engine inventory system, unreal engine 4 inventory system, unreal engine 5 inventory system, ue4 inventory system, ue5 inventory system
Id: TcTxSyk8Vks
Channel Id: undefined
Length: 27min 51sec (1671 seconds)
Published: Wed Dec 02 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.