Skip to content

How to Setup Inventory

Dominik Pavlíček edited this page Jul 26, 2022 · 11 revisions

How to setup Inventory Manager.

Attach Inventory Manager to GameState used with GameMode.

C++

.h

In the protected section (this is not necessary, however, I suggest placing the Variable in the protected section) add this line:

UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category="Inventory") class UInventoryManagerComponent* InventoryManager = nullptr;

.cpp

In C++ Constructor of your GameState class add those lines: InventoryManager = CreateDefaultSubobject<UInventoryManagerComponent>(TEXT("InventoryManagerComponent"));

You will need to add header include in the top, where other includes are: #include "Components/InventoryManagerComponent.h"

Blueprint

Adding a new Component in Blueprint is faster and easier. Open your GameState class, select Add Component and find Inventory Manager Component.


How to setup Inventory Component.

Attach Inventory Component to PlayerController used with GameMode.

C++

.h

In the protected section (this is not necessary, however, I suggest placing the Variable in the protected section) add this line:

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Inventory") class UInventoryComponent* InventoryComponent = nullptr;

.cpp

In C++ Constructor of your PlayerController class add those lines: InventoryComponent = CreateDefaultSubobject<UInventoryComponent>(TEXT("InventoryComponent"));

You will need to add header include in the top, where other includes are: #include "Components/InventoryComponent.h"

Blueprint

Adding a new Component in Blueprint is faster and easier. Open your PlayerController class, select Add Component and find Inventory Component.


How to setup Inventory Widgets.

In order to make all Widgets work, there are two steps required.

GameState Subclasses

You can use the provided GameState class which comes with the ActorInventoryPlugin to learn how to set up Widget Subclasses.

PlayerController

You can use the provided PlayerController which comes with the ActorInventoryPlugin to learn how to set up Player Controller showing/hiding widgets and storing pointers.

Clone this wiki locally