Inventory System UE5 Pt3
This section of the tutorial will tell you how many of any said item is located in your inventory.
We first are going to open up our player character and the ItemTest blueprints. We are going to start off in our character blueprint.
Go to our Project Settings>Input>Action Mapping and add a new one called Interact. We are going to assign it to the E key. Close out the Project settings and head back into the character bp.
Right click and add the InputAction Interact. When we push this button we only want to interact if we are looking at something. We track this through the look at actor. Let’s do a get LookAtActor and right click and select validated get. Where we look at the actor and interact with ourself.
Let’s then in our ItemTest blueprint go into the interfaces>interact with interface. Off of our Interactor function we are going to get our inventory component and then add to Inventory from to find out what we are adding. In our situation we are saying we have received a carrot and we currently have 1 in our inventory.
Now let’s head back into our first person character. We are going to add a branch saying if our interaction was a success we are going to go into the inventory and get the inventory contents and get Keys and get a copy of 0 and get a print string of the name of the item.
Now when we look at our cube we see it and when we press E we recognize it as a carrot.
After we have added it to our inventory we have to destroy the object from our game. Back on our ItemTest tell it to destroy the actor.
We are now going to show this to the player by using the UI, We are going to create a new blueprint if you followed one of the previous tutorials on CommonUI we will be using the same project so it is already setup. If not please refer to how to use commonUI, or if you are knowledgeable on UI proceed forward. We are going to use a commonUIActivatableWidget and name it InventoryMenuScreen. On the DesignedTab we are going to bring in an overlay, the common border we had previously made, a vertical box, a common text (Variable), and a wrap box (Variable).
Now let’s head over into the Graph. We are going to create a new variable called Inventory Name(Text) and make sure it is able to be seen. We then are going to create another new variable called InventoryComponent (InventoryComponent).
Next we are going to head back over to the designer and we are going to create the individual item names. We are going to create an new commonUIActivatableWidget called InventoryMenuSlot. We are going to bring in an overlay, SizeBox, a common border (Variable), and a common text (Variable).
Next head over to the graph. We are going to add 2 variables. Quantity (Integer) and ItemName (Name). Make sure they are both instance editable and expose on spawn.
Connected to our event Pre-Construct we are going to get the Quantity Text and set the text to our Quantity making sure it is greater than 1. If so we are going to get from the data table the name of the object on the row. If found we are going break and get the thumbnail and set the brush from texture and the brush color.
Head back over to the InventoryMenuScreen head over to the event graph and under Event construct we are going to get our inventory component and get our inventory content from it. We are going to get our keys and for each key we are going to create a slot on our menu with the name and quantity and so it in appear our UI
That’s it for this part next part is getting it on the UI.