Starter Inventory Customizations
Look At Based Pickup
Overriding the default proximity based system, with a look at based system is fairly straightforward, with just 3 primary steps.
First create two new custom events in the item_base event graph that will hook into the proximity logic. I labeled these "Player is looking at item", and "Player Looked Away" connect them to the graph as shown.
Next add the function "Remove Interaction UI" to the Item_Base function "Add to inventory" as shown. this is needed cleanup step for this new pickup method.
Adding a new Remove Interaction UI
Add lastly you will create a line trace event that on overlap with an item_base object will call the "player is looking at item" and "player looked away" events on the specific item. The system behaves normally from this point, so it will create or remove the interaction UI allowing you to pickup an object from a distance of your setting.
Line trace based pickup added to firstPeronCharacter
This example is created in the FirstPersonCharacter Blueprint, Connected to the event tick event. You can also adjust the distance of the linetrace by the adjusting the float value that multiplies the forward vector as noted in this image..
Adding A Basic Save System
Extending the Starter inventory to include a save system is very straightforward. This quick tutorial will cover setting up the base save game object and how to write and read the players inventory to it. This allows a persistent player inventory between game sessions. You can then take that further to save different information such as player health, their custom name or stat information or even items dropped in the world.
Create a Save Game blueprint by selecting create Blueprint Class and searching for save game. I named it MySaveGame.
Open that file, inside when need to create variables for each thing that we want to save. In this example case we are saving the player inventory list. So, create a new variable of type "Inventory Structure" and set it to an array. This should exactly mimic the variable used in the inventory component that we want to save the data from.
Next, Create the save logic. I placed my logic inside my GameMode, but the location can vary depending on what you need. If you create a new game mode, just make sure your level is using that game mode.
the basics of the saving the file are as follows,
Gathering the data you want to save
Creating the save game object (this uses the specific save game blueprint class we created earlier)
Placing that data we want saved, in the save game object we just created.
Writing the save file (Save game to slot) the name used here is specific to this save file
Creating the save game object
Adding the variables into save game object.
Save Game Logic
Creating the read/load logic
Load game from slot (use the same name we used when we saved the game to slot)
Get the Data out of the save game object
Place that Data where it is needed, in this case back into out player inventory
Load Game Logic
With that you should have all the basics of a persistent inventory system in place. All that is needed it to create the methods on how and when the save and load functions are called. In the attached picture examples you can see on begin play I check to see if a save file exists and if it does i load it in. You can also see that I made the save file a manual process by enabling input on this blueprint on begin play and also creating an input event associated with the enter/return key that calls the save function. In this example I am also creating and storing a local reference of the save game object in the game mode, but that would not be required and just up to personal preference.
Full Save and Load system, located in MyGameMode
One Note to be aware of is that now that this save file exists, there may be cases where you do not want the save data anymore, such as some testing situations. there are a lot of options but commonly you can either remove the physical file, or create additional game logic to reset the contents back to "empty".
Changing from the default scroll box display to a grid based display
Adjusting the shape of the inventory Menu into 2 rows
I recommended to first try this in a new project so it does not mess up anything you might be working on
Open the file Inventory_Screen which should be located in Content>StarterInventory>UMG
locate the object ScrollBox_InventoryItems nested under the Size Box in the Hierarchy Window. You will want to replace this scroll box with a Wrap Box Panel (this is the easiest method with this system to get a multiple row system)
So Right Click on the ScrollBox_InventoryItems , scroll down the menu to Replace With...and select Wrap Box
Rename ScrollBox_InventoryItems to WrapBox_InventoryItems
In the Details Panel with WrapBox_InventoryItems still selected check the box that says "Is Variable" and compile the blueprint.
attempt to play and you should get a warning with two errors we need to fix. One in Inventory and one in Inventory_List_Item
Select Inventory from the error window.
This should bring you directly to the error inside the function Refresh Inventory UI if not locate that and open it.
There is an error because it is trying to reference the old scroll box. so, within the node with the error right click on the red text that says wrap box inventory items and select break link.. to add child, it should disappear leaving you with just the now good variable. Reconnect that variable to the add child target
Now Open Inventory_List_Item and locate the error at the node scroll widget into view
This is a similar error as the previous but because all your inventory objects should always be visible you don't need this. you can simply break the connection between the Set node and Scroll Widget into view node, and compile. It should be clean and ready to play
At this point, i would go back into the Inventory_Screen file, select the Size Box The contains the new WrapBox_InventoryItems and in the viewport readjust its size and position so it sits where you would like and has room for the two rows that you mentioned. you'll also want to set new anchors so its scales correctly with your resolution when you play.
That's it, if done correctly as you pick up items it will fill the container across the top horizontally, then break to a second row based on the size of the size box.
Adjusting the default Inventory Size
By default, the max item size is set to 5, but this is easily adjustable if you wanted it to be 10 or whatever
Open the Inventory Component, if you did the above fix, this is the same inventory file. it is also found at Content>StarterInventory>Blueprints
In the Variable Panel locate the integer variable Inventory Item Max
Once selected, you can adjust its default value using the details panel, so 10 (but this could be whatever)
and compile. you should now be able to pick up 10 unique objects.