Inventory Manager
The Inventory Manager is the central component that manages Containers and Items available to a Pawn or Player State.
Setup
The Inventory Manager can be added to Pawns or a Player State. Its only pre-requisite is that its owner is able to provide an Ability System Component.
The owner of an Inventory Manager should also implement InventoryManagerProviderInterface
. This interface has a few methods, but the only one should always be implemented is GetInventoryManager
.
If the Inventory Manager is added to a Player State, its Pawn should also implement that interface and either provide the Inventory Manager directly from the state, or store and provide a local copy.
Initialization
The Inventory Manager is self-contained, and it will initialize itself. It requires a valid Pawn (Inventory Avatar) and an Ability System to initialize. This is particularly relevant in the following scenarios:
When the Inventory Manager is added to a Player State, it will retrieve the avatar from it.
In Network Scenarios, the Inventory will wait for the Pawn and ASC to replicate so it can initialize.
You can fine tune how the polling process happens by adjusting the following properties:
AbilitySystemPollInterval
: How often it will check for the Ability System's presence.AbilitySystemMaxWait
: Maximum amount of time the inventory will wait for the ASC to replicate.
Issues during this process will be added to your Inventory Log.
Once fully initialized, the Inventory will notify any classes waiting for it, via the OnInventoryInitialized
. You can also query the initialization state by calling IsInventoryInitialized
.
Default Objects
The Inventory can receive a Layout and Default Items directly, via its properties. However, if you need to have more flexibility, allowing each avatar to define their own Layout or Default Items, you can do so using the InventoryManagerProviderInterface
.
This interface has the following functions that can be used to customize the initialization:
GetInventoryLayout
: Provides the Layout that will be used when the Inventory Manager initializes.GetDefaultItems
: Provides all default items granted when the Inventory Manager initializes.
Query Methods
There are many read-only operations available to query Containers and Items added to the Inventory, which are presented as multiple Getter
and Count
functions.
Operations
The following operations can add or remove Containers and Items. Items in particular can be added from a few different sources. The Inventory Manager is also a gateway for Fragment Operations.
Managing Containers
Containers are added by the AddContainer
function, like so:
Containers are removed by the RemoveContainer
function. You can also remove a container by its unique identifier, using the RemoveContainerById
function.
Managing Items
Items can be added to the inventory in a few different ways:
With an Item Data and optional default memories.
From a Pickup Actor.
From Selected Loot.
Add Item Data
First, by the AddItem
function, which allows you to set optional default memories to the item
If you want to create default memories, similar to what you can do when adding default items to the inventory, then you can use the provided functions:
Add Pickup Actors
Another way to add an item directly from a pickup, via the AddPickup
function. The PickupActor
parameter must be a valid actor that implements InventoryPickupInterface
.
Add Selected Loot
You can also add items that were selected by a Loot Manager, via the AddLoot
function.
Remove Items
Items are removed by the RemoveItem
function. You can also remove an item by its unique identifier, using the RemoveItemById
function.
Additionally, you can set an amount of items to remove from the item's stack. A value of zero will always remove the entire stack.
Replication
Inventory Items only replicate from the authoritative component to the local client. You won't be able to query items and containers in simulated proxies.
Delegates
The Inventory Manager will broadcast its events using the following delegates listed in the table below.
They will broadcast on both the authoritative and local client versions.
Delegate | Event |
---|---|
Inventory Initialized | The inventory has been initialized. |
Container Added | A container was added to the inventory. |
Container Removed | A container was removed from the inventory. |
Item Added | An item was added to the inventory. |
Item Storage Changed | An item's storage has changed. |
Item Removed | An item has been removed from the inventory. |
Loot Received | Loot has been made available to the inventory. |
Loot Dismissed | Loot has been dismissed for the inventory. |