Unreal Engine Inventory Tutorial: Stack Items / Visible Amount

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome to this tutorial in this tutorial i want to show you how you can stack items so when you pick up two items of the same type it will stack and also you will see the amount of items inside the inventory so let's go so the first thing is we want to make the amount of items visible in our inventory so we open up our inventory widget from the loss tutorial and here we go to the item slot widget as well inside here we take a text component put it right here in this case we replace the text with example the number two and then you can place it wherever you want i want it in the right corner down here this one on yeah this looks pretty good so we just call this amount and make it in variable so we delete the number of course and then we go back to our inventory widget go to the graph and we go from the cost to item slot from the as item slot and say get amount there we have our text element and now we just have to set it of course we go from the mountain say set text up here copy and paste this down here like that connect the target of course and then we just go from the amount to the text and it will automatically convert the integer into a text so that's it here then we can close this and now i want to make a parent clause for all items so it makes easier to replicate items create new ones it's much easier so the first thing is we go right click blueprint class actor and this will be the item class open this up and the first thing is like the last time we add up our interface so interact interface of course we need this in every item then we need static mesh just in static mesh as in root component like this and we need done box collision like that so we can leave it because that's the parent clause we will set it for the separated items later so now we need a few variables here the first one will be the item itself of course this will be our item structure that we created last time we just leave it to the default value and the second one will be the variable called contain this will be just in boolean to see if it's already in our inventory for this one we want a new function that will be called append item so the append item will get two input values so in the first place it will be the inventory itself this will be an item structure as an array the second one will be our character and this of course is our third person character object reference as a single variable like that so from here we go one and four each loop with break connect the array of course from the array element we say break item and we get our item structure that we created we go from the item here get it and again we say break item so we have to compare the items inside our inventory with the item that we want to pick up for this we want to compare the name so let's say equal text and compare the name in our inventory with the name of the item for this of course we need a branch to ask connect the loop body with the branch and now we want to set the item actually so we get it set and then we say right click split structure pin and now we are able to set each of these elements here in this case we connect the name the amount the thumbnail and the valid but we can disconnect the amount again because we want that the amount is going up so we take the amount of the item say integer plus integer and connect it of course with the item that is already in our inventory because it's checks is the item already in our inventory if it is so only true case we want to set the amount plus the item that we picked up then of course we want to set the contain to true because it is contained and at last we take out the inventory again and say set array element the target array is of course our inventory the array index is the index and our items our return value here is the item that we want to set from here on we go to the break of the for each loop combine save this and now we take out our contain boolean get it ask for branch of the complete so we go through the branch to see if it contains already the item in our inventory if it does we just destroy the actor then we go from the character get the widget and then we would just want to update our inventory and we connect of course the inventory with the inventory in case of that we not having this item in our inventory we want to add up the new item so we need a new function add item this function of course gets the inventory as well this is an item as an array and the second input is the character of course as some third person character object reference single variable like this and this is also started within four each loop with break again we connect the inventory with the array then we go from the array element and say break item we need to branch here to ask is the item valid and we go from the inventory and say set array element on the false case then we connect the array index with the index connect the item with the item then we want to destroy the actor and at least we go from the character get the widget and then we just want to update the inventory of course we connect the inventory with the inventory and very important we go from the update inventory back to the break then we go back to our append item so we have this false case when we not containing the item already in our inventory in this case we of course just call the add item and then we connect the inventory and the character so the good part now is we go back to our item class here and we say right click create child blueprint clause let's call this book open this up and now we just have to set the static mesh so i prepared this book and this potion we select the book and go to the static mesh here put it right here then we set the box collision a little bit like this go to the book itself and then we just enter the name the amount then the thumbnail and we call this valid and then we just do the same thing for the potion so create a child call this potion open this up select static mesh enter it right here place the box collision like this one and then we just enter the name the amount the icons or the thumbnail and we call this valid and then we just place these actors here inside the world so the book on this chair for example put this book as well here then we place this portion on the table for example and on this table and we now hit play open up our inventory go to this portion press e you can see there's one portion we go to the second one here pick it up as well now we have two pick up this book the book is one pick up the second book and we have two portions and two books in our inventory great so i hope you enjoyed the tutorial if you have any questions please let me know and yeah goodbye
Info
Channel: Seredias
Views: 5,081
Rating: undefined out of 5
Keywords:
Id: UT-c0mzoRG0
Channel Id: undefined
Length: 10min 41sec (641 seconds)
Published: Sat Apr 02 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.