Inventory System
UE5 Inventory and Item System Version: 3.0The inventory system is how we connect and manage our items in our player inventories, banks, and storage containers. It is also used when we spawn lootable containers like a player’s dropped loot on death, or a treasure chest.
For the player's storage systems, the AC_Inventory inventory components are attached automatically to your Player Controller with the AC_InvnetoryItemSystem component, a StashIndex of 0 is used to represent the Player's Inventory. 1 is used for the Player Bank, 2 is used for the Hotbar, and 3 is for the Equipment.
Attaching to the player controller makes it easy to manage if we have to switch or respawn our possessed pawn. For NPCs it is attached to the pawn. The component is built to detect what it is attached to, if it detects it is attached to a player controller it knows it belongs to a player. If not then it knows it belongs to the server. This is important for the saving system, and the multiplayer support.
Changing Slot Count
To change the slot count of your player’s inventory select the AC_InventoryItemSystem you added to your player controller. Navigate to the Player Settings section of the details panel and expand it to expose the InventorySlots variable. This is the number of slots to show in the inventory.
Changing Column Count
To change the column count open up the UI_Inventory and switch to the Graph. Select and then change the Columns (int) variable. This is the value used to determine the number of columns to render.
Changing Window Height
To change the height of the window before the scrollbar appears, open up the UI_Inventory and from the Designer graph navigate through the Hierarchy panel until you find the SizeBox with the MaxDesiredHeight value set to 415. Change this value to the maximum height you want to use.
Overflow Items
Overflow is what happens when more items end up in the inventory then it was designed to carry. While there are checks to prevent picking up items when it is full it is still possible to spawn in more items then can fit.
For example if you fill up your inventory in the example world with loot boxes but leave one open spot, then open a loot box there is a chance you get 3 items even though you have room for 1. The 2 extra items will be marked as overflow items.
The alternative to overflow items is either destroying them or spawning them in the world. Overflow seemed like the best solution from the player’s perspective.
While items are marked as overflow they will have a red cover and become inaccessible until space is made in the inventory by removing items not currently in the overflow.
Show / Hide the Inventory
You can easily show and hide the inventory for the local player using the showInventory and hideInventory global functions. These functions can be found in the BP_SharedFunctions blueprint library located in the Blueprints/Variables/ folder.
Enable / Disable the Inventory
You can easily disable and reenable toggling of the inventory of the local player by using the enableInventory and disableInventory global functions. These functions can also be found in the BP_SharedFunctions blueprint library.