Inventory Component
Introduction
Actor component responsible for tracking data in an inventory
Dependencies
The InventoryComponent
relies on other components of this plugin to work:
- Logger: Used to log useful information to help you debug any issues you might experience
- Game Instance: Used to monitor for input device changes and handle saving/loading game data
API Reference
Properties
Property | Description | Type | Default Value |
---|---|---|---|
InventoryId | The ID of the inventory used when saving/loading the data | FName | |
AutoSave | Should the data in the inventory automatically be saved/loaded | bool | true |
EnforceMaxAmount | Should a maximum amount be enforced for each item? | bool | false |
MaxAmount | The maximum amount of each item | int | 99 |
Events
Name | Description | Params |
---|---|---|
OnInventoryItemUpdated | Event used to notify other classes every time an item in the inventory was updated | Id (FName) The ID of the item that was updated Amount (FName) The new amount of the item |
Functions
Name | Description | Params | Return |
---|---|---|---|
GetItems | Get all the item currently in the inventory | TArray<FInventoryItem> An array of all the items in the inventory |
|
AddItem | Add an item to the inventory | Id (FName) The ID of the item to add Amount (int) The amount to add |
|
RemoveItem | Remove an item from the inventory | Id (FName) The ID of the item to remove Amount (int) The amount to remove |
|
RemoveAll | Remove all the items with the specified ID | Id (FName) The ID of the item to remove |
|
Clear | Remove all items from the inventory | ||
LoadInventory | Load the inventory data | ||
SaveInventory | Save the inventory data |
Blueprint Usage
You can use the InventoryComponent
using Blueprints by adding one of the following nodes:
- Ultimate Starter Kit > Inventory > Get Items
- Ultimate Starter Kit > Inventory > Add Item
- Ultimate Starter Kit > Inventory > Remove Item
- Ultimate Starter Kit > Inventory > Remove All
- Ultimate Starter Kit > Inventory > Clear
- Ultimate Starter Kit > Inventory > Load Inventory
- Ultimate Starter Kit > Inventory > Save Inventory
C++ Usage
Before you can use the plugin, you first need to enable the plugin in your Build.cs
file:
PublicDependencyModuleNames.Add("USK");
The InventoryComponent
can now be used in any of your C++ files:
#include "USK/Inventory/InventoryComponent.h"
void ATestActor::Test()
{
// InventoryComponent is a pointer to the UInventoryComponent
TArray<FInventoryItem> Items = InventoryComponent->GetItems();
InventoryComponent->AddItem(Id, Amount);
InventoryComponent->RemoveItem(Id, Amount);
InventoryComponent->RemoveAll(Id);
InventoryComponent->Clear();
InventoryComponent->LoadInventory();
InventoryComponent->SaveInventory();
}