Blueprint Inventory

From Epic Wiki

Blueprint Inventory

This wiki page will teach you how to make a simple inventory system. I based my initial work off the forum post found here . The core features of this system are:

  • Extendible BaseInventory class
    • Inventory weight and max slot size
  • Extendible BaseItem class
    • Item weight
    • Stackable (optional)
  • Structures for inventory slots

BaseItem

Create an Actor Blueprint and give it a name of BaseItem (or something else if you want).

Add a sphere collision component and rename it to PickUpRadius:

SphereCollision settings

Add a static mesh component and rename it to ItemMesh:

StaticMesh settings

Create the following variables:

BaseItem variables

InventorySlot

Create a Structure Blueprint, name it InventorySlot and add the following two variables:

InventorySlot structure

BaseInventory

Create an Actor Blueprint and give it a name. We will use BaseInventory. Add a StaticMesh component and make it the root component.

Add the following variables:

BaseInventory variables

Macros

CanItStack
CurrentWeight
HasInventorySpace
HasPartialStack

Functions

AddItemToInventory

Pick-up Functionality

BaseItem

SphereCollisionEvent

Your Character

On your character blueprint, add the following variable so that the character has an inventory we can reference.

CharacterInventory

Then, spawn an instance of BaseInventory (preferably on BeginPlay) and assign it to the variable we created above.

InventorySpawn

Testing

Place a BaseItem inside your level, and press play. When you walk over the item, you should see a printed message:

ItemAdded