The inventory for this game is one of the more complex features it has, it allows the player to pick up items as well as view them within the inventory.
Below is the basic structure of the inventory system, I am planning later to stylize it more, but at the moment I have got the basic version. Within the boxes are several layers of scrollbars and text boxes so the items won’t stack on top of each other.
Next, I simply needed a button to open up the inventory, within the input settings I created a function called “openInv” and set the key to ‘I’ Within the player character blueprint all I needed to do was connect this function to the inventory widget.
Another function was created which made the ‘E’ button a pickup function. After this, I needed to work on how the player will pick up items. I set the reference to the player character at first but changed it to the player cursor, this means that the player can click on an item with the mouse and pick it up.
A variable needed to be made before the rest in order to judge how far away the player can be in order to pick up an item, which can be modified at any time. To pick up the items I used a function which traced actors with lines, then when they come into contact the actor is destroyed. The actor would be added into the inventory widget after interaction and a sound will be played.Below is the code which destroys the actor and adds into the inventory. Also what lets me view the item name and descriptions. The items would be added into a separate widget that displays the clickable items as seen in the bottom two blueprints, this is to stop the items from stacking or deleting themselves.
I used actors as pick up items within my game, this is because they are easily duplicated and changed. I had to first create a master item and then create children out of that one.Below is the finished result, as you can see a note has appeared within the inventory box, and when clicked it opens up with an image as well as a description that is changeable within the actor blueprints.