Inventory System
The Inventory System manages Containers and Items, providing a flexible way to handle inventory logic across different actors.
It should be added to an Actor or Player State, depending on your design goals.
Actor: Inventories with limited persistency, such as those for chests, vendors, or enemies, should have the Inventory Manager added directly to the actor.
Player State: Players that require an inventory to persist over multiple levels should have the Inventory Manager added to the Player State.
Inventory Manager Component
The Inventory Manager Component is the main component in the system and should be added to any actor or player state that needs access to an inventory.
Add the Inventory Manager Component
In your Pawn or Player State, add the Inventory Manager Component.
The component can be added using either Blueprint or C++:
Header
public: ANBSPlayerState(const FObjectInitializer& ObjectInitializer); private: /** Inventory Manager component. */ UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Components", meta = (AllowPrivateAccess = "true")) TObjectPtr<UNinjaInventoryManagerComponent> InventoryManager;Implementation
#include "Components/NinjaInventoryManagerComponent.h" ANBSPlayerState::ANBSPlayerState(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) { InventoryManager = CreateDefaultSubobject<UNinjaInventoryManagerComponent>(TEXT("InventoryManager")); }
The Inventory Manager provides important properties that can be used to adjust its behavior.
Property | Description |
|---|---|
Default Container Query | A query used to identify the default container in the inventory. |
Initial Containers | All containers added to the inventory by default. |
Initial Items | All items added to the inventory by default. |
Item Processor Class | A dedicated class containing all the logic that determines which containers should receive new items. |
Items Per Tick | How many items can be processed per tick. This keeps the item processing from consuming too many resources per tick. |
Should Fail on Missing Ability Component | If true, initialization will fail if an Ability System Component is not found. |
Ability System Poll Interval | How frequently (in seconds) the Inventory Manager checks for an Ability System Component during initialization. |
Ability System Max Wait | Maximum time (in seconds) to wait for the ASC before giving up and potentially failing the initialization. |
Automatically Load From Disk | Whether the Inventory Manager will attempt to load inventory data from a save slot automatically during initialization. |
Save Game User Index | Index for the Save User file. You can create dynamic behaviors by extending |
Save Game Slot Name | Name of the Save Slot. |
Ability Component Binding
The Inventory Manager Component will automatically bind to an Ability System Component if the function ShouldBindToAbilityComponent returns true.
By default, this will happen if the component owner implements AbilitySystemInterface or, in case of a Player State owner that does not implement the interface, having its Pawn implementing the interface.
Initialization States
While initializing, the Inventory will go through several states, each representing a distinct step in the process. The
current state can be viewed through the Gameplay Debugger.
State | Description |
|---|---|
| Initialization has not started yet. |
| Inventory is waiting for the Ability System Component (ASC) to become available. |
| Inventory is connected to the ASC and will begin initializing items. |
| Inventory is loading data from a saved game file. |
| Inventory successfully initialized using saved game data. |
| Inventory is initializing from default containers and items. |
| Inventory successfully initialized using default settings. |
| Items and fragments are being fully initialized. |
| Inventory has completed initialization and is ready to use. |
| An error occurred and the inventory failed to initialize. |
You can query the current initialization state using the following functions from the Inventory Manager:
Function | Description |
|---|---|
| Provides the current initialization state. |
| Utility function to confirm that the inventory has been initialized. |
| Informs if the inventory was loaded from a save slot. |
Inventory System Interface
The recommended way to retrieve the Inventory Manager is by using the GetInventoryManager function in the NinjaInventoryFunctionLibrary.
This function can retrieve the Inventory Manager from Actors, Controllers, and Player States, by searching in the most likely locations.
However, to avoid repeated component lookups, you can optionally have the Actor or Player State implement InventorySystemInterface, which is recommended.
Add the Inventory System Interface
In your inventory owner (Actor or Player State), add the
InventorySystemInterface.Implement the
GetInventoryManagerfunction so it returns the Inventory Manager Component.
Header
Implementation

