Inventory System
The Inventory System is managed around Components, that can
be attached to the Player or to the Interactable Actor. By
default the InventoryCore Component is added to the Actors,
which are eligible for containing and transferring the
items. PlayerInventory Component on the other hand, is
derived from the InventoryCore - it already has all the
necessary functions plus some additional ones that were
added specifically for the Owning Player. Since all the
functions/events are inherited from InventoryCore they can
be modified and extended.
Inventory Component Tree for Player and Interactable
Object
Overriding a function inside PlayerInventory Component
Treasure Chest and Vendor - Inventory parameters
comparison
Whenever an Item is picked up, bought from a vendor or
simply moved to the player inventory, it will be handled by
a special function called 'Transfer Item from Inventory'. It
works in both directions - an Item can be transferred from
Player to the Actor Inventory and opposite, main difference
is changing the Receiver and Sender Inventory Component.
When Drag Dropping an Item it is required to specify the 'In
Slot Data' input parameter. In multiplayer enviroinment you
must use a Server call of this function - Target will always
be the PlayerInventory Component.
Transfer Item from Inventory graph
Transfer Item from Inventory (Server call)
Transfer Item from Inventory (PlayerInventory) function
flowchart
Unequipping an Item from Equipment is handled by 'Transfer
Item from Equipment' function. Target and Sender will always
be the same. When Drag Dropping an Item it is required to
specify the 'In Slot Data' input parameter.
Transfer Item from Inventory (Server call)
Transfer Item from Inventory (Server call)
Inventory Component contains lot of useful Event
Dispatchers, which can be binded inside of a blueprint class
or added as Events inside the Owning Actor. They are
primarily used to communicate with widgets, for example to
Refresh the Inventory Slots. Some of them are added as
Events inside the Player Controller.
Override Player Inventory Delegate inside Player
Controller
Bind Event Dispatchers inside Widget (PlayerInventory in
this case)
Override InventoryCore Delegate inside Interactable Actor
Initial Items can be added to the Inventory Component by
using 3 different methods: Adding All Items from DataTable,
Adding Single Item from DataTable, Adding Random Items from
DataTable. Items can be added to an Actor in the Level or
inside the Actor Class (that will be spawned at some point).
Different methods of adding initial items to the inventory
component
Each Inventory Component can use multiple Inventory Panels,
currently the Items can be splitted between 4 Inventory tabs
(P1 = Armor & Weapons, P2 = Consumables, P3 = Crafting
Materials, P4 = Quest Items/Other), it can be assigned
inside Item Class. By default only Player Inventory is using
4 panels, this can be changed inside Inventory Component
Class Defaults. Base on the enum you can Refresh the
individual Inventory Tab or Switch to the tab you just
selected (by clicking on button or pressing an input).
InventoryCore is using only 1 Panel to store the Items in
the array
Player Inventory is using 4 Panels, each has individual
Inventory Array
Basing some Widget functionality on Inventory Panel
enumeration
Inventory Component can use or not use Inventory Size, it
can be toggled in the Component Class Defaults [Use
Inventory Size] boolean. Setting it to True means the Array
will be resized and filled out with empty slots (i.e. Player
Inventory, Vendor, Storage). In this case the Inventory can
become full at some point (resulting in displaying the
pop-up message on screen). Each Inventory Panel has a
separate Inventory Size parameter to modify. Setting
Inventory Size to False means it won't have any empty slots,
the Items will be added as the next element of an array.
Currently it's used for Item Pickups, Chests, LootBags, etc.
Changing Inventory Sizes in Class Defaults
Building Inventory Array base on 'Use Inventory Size'
boolean
Getting Inventory Array and Size for specified Panel
Inventory Component can be checking Owner Gold, for
example when trading with a Vendor. The Actor already has
this option assigned as True. If the stacked Item value
would be greater than current Gold, then Transferring of
the Item will fail - function 'Has Enough Gold' is used in
that case. The base amount of Gold can be changed by
setting 'Owner Gold' parameter.
The Component can also use Inventory Weight - currently
only used for the Player Inventory. Exceeding the Max
Inventory Weight only changes the displaying Inventory
Weight text in the widget at this moment, but this can be
extended base on the project specifics.
Changing Inventory Sizes in Class Defaults
Building Inventory Array base on 'Use Inventory Size'
boolean
Getting Inventory Array and Size for specified Panel
There are few important core functions inside the
Inventory Component. You can for example retrieve an item
from the inventory by ID, Slot Index or ItemData. You can
get the Array of Items in the Inventory or of specified
type. Find the Empty Slot and amount of emtpy slots in the
inventory. Adding an Item to the Inventory Array requires
specifying Item Data and Slot Index (to which it should be
added). Additionally before adding an item you can also
check for Partial Stack in the Inventory.
Getter functions inside InventoryCore Component
Adding and Removing an Item from the Inventory
Checking for Partial Stack for Stackable Items