# Inventory Manager

<div align="left"><figure><img src="https://3303637552-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOAGs3il6rJbkejwPOlEP%2Fuploads%2FOXndO6hKeLj0uEuE8Vaf%2FActorComponent_64x.png?alt=media&#x26;token=b00844b2-cbc3-4f89-9f4b-d2c8e193007c" alt=""><figcaption></figcaption></figure></div>

The **Inventory Manager (AC\_InventoryManager)** provides all the necessary functionality to handle player Inventory & Storage, including adding, removing, and using items, managing currency, and updating the UI in runtime.

It is added to the **PlayerController** class by default **(PC\_SoulslikeFramework).**

### **How It Works**

1. **Initialization**:
   * Initializes all item slots and prepares the inventory UI for use.
   * `InitializeLoadedInventory` method tries to load inventory data from the relevant save slot.
2. **Item Handling**:
   * **Adding Items**: Items can be added through the relevant item asset or a Gameplay Tag.&#x20;
     * Automatically increments quantity if the item already exists, or creates a new slot if it doesn’t.
   * **Removing Items**: Removes a specific quantity or deletes the item from the inventory entirely.
   * **Using Items**: Triggers the item’s `OnUse` function, spawning the appropriate actor (e.g., potion, consumable) and applying effects.
   * **Triggering Actions:** Triggers the item's provided `ActionTag`, queueing it through the Input Buffer.
3. **Inventory Queries**:
   * Supports multiple ways to query inventory data:
     * **HasItem**: Checks if a specific item is present.
     * **GetAmountOfItemWithTag**: Retrieves the quantity of items matching a specific tag.
     * **GetEmptySlot**: Finds the next available empty inventory slot.
4. **UI Updates**:
   * Event dispatchers such as `OnInventoryUpdated` and `OnCurrencyUpdated` ensure the inventory UI is always in sync with changes.
   * The `GetInventoryWidget` function links the UI directly to the inventory component.
5. **Saving/Loading**:
   * The `SaveAllInventory` function serializes the inventory state, including items, quantities, and configurations.
   * Inventory data is restored on load using the `InitializeLoadedInventory` function.

### Example Usages

The provided **Parent Door Class (B\_Door)** has a great example on utilizing the Inventory Manager for checking if **multiple key items** (e.g, KeyA x1 & KeyB x4) exist in inventory before unlocking a door:

<figure><img src="https://3303637552-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FOAGs3il6rJbkejwPOlEP%2Fuploads%2FfUrSuEc9aMKhM9SjZlgU%2Fimage.png?alt=media&#x26;token=b3b6f3f1-aeee-4d32-a403-2b6c036e3ab5" alt=""><figcaption></figcaption></figure>

Rest of the functionality is mainly handled by **Inventory Widget.**
