Inventory System UE5 Pt1
We are going to create a data table. A data table holds all of the information about each individual item.
We are going to create a new folder called inventory system and then create a blueprint that is a structure and we are going to call it ItemStruct. A struct is a collection of variables. So we are going to give our item a display name (Text), Description (Text), Thumbnail (Texture 2D), and a 3D mesh (Static Mesh), Buy Cost (Float), Sell Cost (Float), IsStackable (Boolean).
We are now going to go back to the content drawer and create a miscellaneous >data table. In here we want to select our ItemStruct type and name it ItemDataTable.
When you open it up you will see the columns `we had created. We then want to create a new item so add a row and fill out the information related to that item. For the example we chose a carrot.
Next we are going to create an inventory component that we can attach to other items like chests to open them up. We are going to create an actor component blueprint. We are going to name it inventory component.
We are going to create a variable called Inventory Content. This is going to be of type name and type map. We are using a map so we can refer to how many of an item that we have.
We now are going to create 3 new functions. They are going to be called AddToInventory, RemoveFromInventory, and SwapWithInventory. Their purpose is self explanitory. Let’s start in AddToInvetory.
In AddToInvenory we are going to add Inputs to our function. They are ItemName (Name) and Quantity (Integer).
We are going to drag our get inventory and add (Map). This will override the existing item. So we need to see if we already have that item. We will need to find out item name. If the item is found we will select the A value if true and B value if not.
We not are going inventory component to our character. So go to our character blueprint and add the inventory component to add it to the character. On the right side there are some default settings.