How to Make a Simple Inventory System in Unreal Engine 5

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's up guys welcome to new Unreal Engine 52 and today I'm going to show you on how to make a simple inventory system it's going to be a very easy video to follow so let's get started uh first of all I'm gonna go ahead and create a new folder um just basically to have things more organized but of course you can you know organize it as you want so let's go ahead and create new folder and I'm just going to call it inventory let's go ahead enter and the first thing that we are basically going to create is a blueprint class and uh it's gonna be a actual component so it is a and here's gonna leave our inventory and we're going to add it into any actor that we want in that case it will be a player later on but of course we could also add it into our own AI or whatever so it's very uh convenient to basically do it in a component so let's go ahead do it BBC for blueprint components and inventory let's go ahead and create it and open it up okay so I'm gonna go just go ahead and delete this uh beginplay and the event tip we don't need them right now so we're gonna go ahead and create a new variable um this is going to be our inventory array okay if you don't know what that array is it's basically a list of items okay and so literally we're gonna call it inventory and basically it's going to be an array of strings we're gonna control our inventory in a very very simple way which is just going to be by the name of the item itself so we're going to go ahead and answer the type string selected and then in um variable type we can go ahead and click and add it into array so now it will be collection of strings not just one string okay so let's go ahead and compile this so what we have to do right now is to implement the ability to add things into this inventory so we're going to create one function scope here create a new function and this is going to be add item to inventory so for this what we're going to do is get our inventory drag it we're going to get it and then we can just drag this in place and add node which will basically um add an item into our our array so let's click add let's go ahead and connect this and then what we can do is have an input into our add item to inventory so what we can do is just drag this and pin it over here so basically now um we'll be passing the new item into uh the inventory uh okay yeah so we can go ahead and click save and we can also go ahead and print this string of the new items just make sure that it's basically adding okay let's go ahead and make things a bit nicer there we go okay okay so now we're going to do is go into our character blueprint now I will be using the third person uh blueprint but of course you can use the first person or your own class or whatever okay it will work for any type of blueprint of course so the first thing that we're going to do is in components we're going to add our inventory components so let's go ahead and use search uh for inventory I'm going to go ahead and edit on here we can leave the name like this and there we go okay so now what we can do um is um create an interface to basically be able to pick up items running for okay but actually first let's build the pickable item that's gonna be basically on the floor so let me go into my inventory folder and let's go ahead and create a new uh blueprint class which is going to be of type actor it's going to be RBP item now I do have an advanced pickup system an equipment system so if you want to check it out I will be leaving in the description um so yeah now let's continue so let's go ahead and open this item and I'm just gonna add a static mesh to basically have a model um and you know for this example I'm gonna be using um I believe that I have a sword in this um project no okay so I'll I'm just gonna add a cube okay yes you have something and I'm just gonna make it smaller because right now is absolutely huge and then uh what we can do is yeah live like this so let's add a new component which is going to be our Collider a sphere Collision this is going to be the radius that we can interact with this item and basically pick it up so this is going to be a basically large streamer okay now make sure that down in Collision uh presets is set in overlap of dynamic now in sphere radius we're going to make it a bigger like for example uh something at 70. so if we are inside this radius we can basically pick up this item all right so now we can go ahead and compile and Save let's go into the bench graph and we're going to create a new variable which is going to be item uh yeah I just item and this is going to be type of string and then we're going to go ahead and click this I which will expose that in details panel so basically we can access it later on and change its parameters since in the scene um so in here we'll basically Define what item it is okay so now we can go back into third person map and we can just drag our BP item over here into the floor great so now let's create an interface to basically be able to pick up this item now if you don't know what an interface is it's just a way of communicating communicating um through blueprints um without needing to cast directly into that class that's my way of describing it okay so let's go ahead and go and create a blueprints interface it's going to be BPI um pick up okay so let's go ahead and open this up and you will see that we have a new function we created automatically so we're going to rename this into actually pick up item okay so now we have to add an output which will give us the item that we are basically going to go ahead and you know uh pick up so in here you have a new parameter is going to be item and uh this is going to be a string so now we can compile and save and close this guy up and then what we can do is go into class settings and add here and in an interface it's going to be a BPI pickup and then we can double click in here and we'll have interface without return node so what we will do is rent here uh like a string and it's gonna be um item picked okay and then what we're going to do is return the item variable that we created earlier so now we can go ahead and compile and say so now let's go back into our third person character and I'm gonna go over here and basically what we're going to do is when I press the E key we're gonna find uh the items nearby and pick it up so I'm gonna go ahead and make a for each Loop I'm gonna search for all the overlapping actors get overlapping actors and then we can put a class filter that will be only for um BP items so now we can make sure that it does implement the interface um so just avoid errors BPI pickup and then we can return value and make a branch so we only do this if well it's true and then in the array element we can call our pick up item of our BPI b cup interface and then it will return us our item so now we can just get the bpc inventory component and then we can go ahead and call the add to inventory function that we created earlier and then just plug in item into here okay so now we can go ahead and go to the first map press play and we can go into our item press e and you'll see that we have a print going up into item picked really cool so um the next thing that I'm going to do is the item set it to be for example uh let's say wood um so you can see that you can apply the item um just right directly on the details panel so uh one more thing to do is in the EBP item go into bank graph I create a custom event which is going to be um uh destroy the item and this will just make it delay it's not the way of 0.1 seconds and then once it's completed we'll basically destroy this actor is because if we uh do it directly we destroy the um the actor before we return it it will not return anything because it's destroyed and we cannot apply a delay on the function so we have to create a custom event so now we can go R destroy item and there we go so now uh if we go ahead and pick it up you will see that it will be destroyed and basically pick it up and you see that we have also a good input over here so now let's make our inventory widget our dual height to display our inventory so let's go ahead and create a new widget uh blueprint it's gonna be a user widget WP and it's going to be our inventory so now let's go ahead and open it up so once it's open we can go ahead and go into the palette and add a canvas panel into here we go it closes up and uh now what we can do is basically add a um vertical vertical box so we will basically have a list of all the items that we basically currently have so let's go here gonna kind of Center it over here move it as uh you know big as we want our item list B and then you can just get the anchors and put it into the corners so it will resize correctly to the screen very important Okay so now that we have that we can just place a text over here on top of this and uh we can use uh you know put for example inventory you also have a nice title and then we can use a pair and then put our anchors again over here okay compile and save so now we're gonna go back in the third person character just up here I'm gonna press if I press the um Outreach tab Tab Key um I will go ahead and open this panel so got to do is get a flip-flop because we're gonna press it once to open it and then close it so in a we're going to do is create a widget which is going to be basically our um uh it would be inventory the only implies going to be our get player controller as we are basically going to be controlling it and return value it will um actually first of all right click and then promote travel so we have a nice variable and it's going to be the inventory widget and then this we're gonna drag from this and then add two viewports so uh into the player's perspective screen and then in um we're going to do is go into B and drag our inventory widget get it and convert it into validated git so and if it's valid we'll just remove from parent so we'll basically remove it and then we'll set it the variable to be just empty and right before we do create our um are inventory but we can just drag this get it and then also I value it get so if it's not valued there we go okay I just changed the tab to the E key I don't know why the tab wasn't detector I guess it's an unreal thing but uh now we press e you can see that the inventory uh title goes up there so um one last thing I go here and um set input input to be uh game mode and UI and then what we're going to do is get these player controller and then we're gonna set the mouse uh uh show mouse cursor to be true and then in here we'll set input to be um game only and get again the player controller over here and then set the mouse to be showcasing false okay so now we press E I have the mouse into the inventory okay so um I just missed a player controller here over here sorry there we go and now you will see that the mouse the camera doesn't move okay great so uh the next thing we're going to do is create our another item um sorry another widget that will basically add into this vertical um list over here so let's go ahead user interface with your blueprint use a widget it's going to be your WB underscore um item slide so let's go ahead and open it up and the only thing that we're going to need is a text so just drag it into the screen and then on on here you say um the side on screen so it will only be using this size basically so uh on here we're going to do is Place item name so text and we can literally use compile and say for now so when I'm back in WB inventory you will see that if I search for a slot I find my weepy wdp item so sorry and if I pass it over here you will see how it adds into the list and if I start to duplicate it it will be adding as a list basically which is exactly what we want so we're achieving what we want so the next thing that we want to do is add it dynamically when we basically you know get an item and add it into inventory so go into the graph over here I'm going to delete all this stuff and we're going to create a new custom event that will go when we pick out an item which will be add item sorry item to um to list UI maybe not the best name but anyway so we need now to access on this list over here so just get here this sorry list vertical and this is going to be is variable so now it will appear here we can get it and literally we can just say add uh child and plug it in and now we can select the content um so in here this is a widget reference so what we can do first is uh create our widget it's gonna be a slot and then just get the originality into content and get a new player get player controller all right there we go so now if we go into bpc inventory and into our function to add item to Mentor um right up to here what we'll do is access our um layer a player's uh inventory so okay get owner into our third person character and then we can plug this in over here and now we can access our inventory which and now we can call our function which is going to be um what was it list UI item to this UI there we go so if now I press this and go over here so you'll see that we have our item over here um now there will be a problem in a second but let me open the item and press e and you will see that it's adding to the list but now if I do go here get at it and then open it you will see that it's not displaying this basically how um exactly we have an error what is happening is that basically we're creating a new widget every time and removing a new widget every time so we don't need that we don't have to do that so um what we can do is get our inventory widget and instead of remove it every time we can set the visibility to be visible on here when it's valid so the first time we'll have to create it but then no and then we go back into here and then here instead of removed from parent we can again set visibly to be hidden and then plug it in over here we have to do one more thing because if we don't press tab on we open we get an item it will not be it will not be added so what we're going to do is go into the E here and then do this basically Doom and then beam and then get it and then set basically to hidden so we had to create a widget before and so let me let's get this let's move it before paste it plug it in I know that this part is a bit confusing right now um but it's just logical on how uh basically right now is working uh so now we can basically pick it up and open inventory and we'll see that is already here great and so now we have to communicate the number uh the names right of the item to you know add it on here so what we can do is on item here and add an input which is going to be item name and this again is going to be a string and then what we can do is go into slot and we're gonna make this the item name and basically mark this as variable compounds so now what we're gonna do is [Music] um you got the value over here and it will be get um item name and then what we can do is just directly set the text there we go to be what we receive on the item name it will convert it to a string text and now in the uh third person here uh in the bpc inventory sorry we can just get the um the item name is plug it directly over here so if I now go ahead and pick up the item I'm gonna go ahead press e you can see that I have wood over here added into my item and now I can do the same I can basically duplicate this and put in here for example Stone and duplicate it again and put for example um I don't know sword so now if I press play you'll see that I can start picking up all the items um and you see that they start actually you know being applied over here now you saw that I just replaced um the item I just realized that we have two issues so in the Y and when we set it to to be nothing let's go ahead and remove that plug it in directly and on here and we have it on is valid but in sorry it's not valid to here but it's valid just apply directly into the forage Loop so now if I press play and I come into here I can pick up all the items and open the inventory you can see sword would and then I can pick up another item and then we have sort of wood Stone and that's it guys that's pretty much deemed into resistance I'm just going to make one more change here in the inventory just to make it look a bit prettier I'm just gonna add some blur on it some black background blueberries and just put it over here kind of matching uh the area there we go and let's go ahead and put the anchors on each size over here we go and then the blur strength is going to be like 10. or seven yeah seven and then we're gonna make it on top of everything so it will not affect the text and uh then I'm just gonna get a image put over here so let's just resize it done like this we go it'll be black and then a 0.2 of opacity and then we can put it right on top of here the background blur now we can compile save actually I just missed the anchors remember to plug it in if not and we change the screen resolution resize it it will everything messed up it's another press play pick up the items and if I open them so you will see that now it's a bit more peachy um you can see that is like a panel better display of course there's a lot of things to that but yeah so that's it guys if you enjoyed the tutorial and found it helpful I will check like the video and subscribe to my channel I have lots of Unreal Engine factorials at this one so if you want to check out go ahead now with all I said [Music]
Info
Channel: Gorka Games
Views: 61,090
Rating: undefined out of 5
Keywords: games, videojuegos, unreal engine, unreal engine 5, ue5, inventory system, tutorial, quixel, megascans, unreal engine tutorial, inventory system unreal engine, ue5 inventory system, ue5 inventorytutorial, ue5 simple inventory, unreal engine inventory system system, unreal engine 5 how to make a inventory, unreal engine 5 pick up items, unreal engine how to easily make a inventory system, unreal engine 5 easy inventory tutorial, how to make inventory system in ue5
Id: khjUY5To7qI
Channel Id: undefined
Length: 23min 0sec (1380 seconds)
Published: Sat Nov 12 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.