Create a folder called Inventory
Create a BP component actor, name as BPC_Inventory
Add inventory array String variable
Add new function to implement the ability to add things into inventory:
name function as Add item to Inventory
create graph as follow (drag ADD to centre of function node, to make new item output):
Go to 3rd person BP:
Search and add BPC Inventory Component
Create a BP actor called BP_Inventory Item (set in pickup tutorial, add a cube as mesh, collision box, and variable)
create variable called item, set as string and make it public
Create a BP interface, name as BPI_InventoryItems
Name the function as Pick Up Item,
add Outputs, change to string and name as item
Go to BP_Inventory,
Class Setting, choose the interface
double click the pick up item interface on BP inventory graph
Go to 3rd person graph, add pickup nodes by E hotkey
Now the item can be picked up (showed on print string) in scene
To destroy actor after pickup:
Back to BP_inventory
Event graph:
Pickup item function:
Create Inventory Widget:
Name as WB_Inventory
To 3rd person BP
(promote variable inventory widget)
Now click tab will show the widget in scene
Continue after add to viewport (show mouse cursor)
Create a new widget, called WB_ItemSlot
Just add a canvas and text, name as Item Name, change to Desired on screen size
Back to WB Inventory,
Rename the Vertical box, and make it is variable
go to event graph
Go to BPC inventory, function (add item to inventory)
Now the inventory only shows picked item when it’s already opened (tab). Coz everytime a inventory list is opened, old one is removed and a new one is created.
To make picked items showed anytime once pressing tab
Revise the 3rd person BP graph:
Also on press E (pickup) graph:
Add item names on inventory list:
In WB Inventory event graph, add input variables on custom event node:
Go to WB ItemSlot, rename as ItemName and be variable
Back to Inventory event graph
In BPC inventory, connect new item below:
Name the inventoryitem drag in scene, e.g. wood (make BP inventory Variable item be visible first)
Now when picked up, the inveotry show the item name:
Now the old inventory items will be replaced by newly picked item, to solve it:
In 3rd person BP:
Delete Set inventory widget node between set visibility and set input mode game only node
Also, connect the follow is valid node to for each loop:
Modify Inventory list:
In WB Inventory
Add background blur with follow setting:
and image (black with 0.3 alpha)