Skip to content

Quick Start: Containers and Layout

Now that the Inventory System setup is done, you will see how to create your first few items that are just equipped to the Inventory Avatar. In this example, we'll use a sword and a shield, but you are free to follow along with any other equipment pieces that are pertinent to your project.

Crate Inventory Containers

The first step is to configure containers that will be available to inventories.

Containers can represent a few different things in the inventory.

  1. A region in the inventory where items can be stored.
  2. An equipment container (or equipment slot) where a single equipment can be placed.
  3. The storage of another item that is represented in the inventory.
  4. A non-accessible area from an inventory where lootable items can be kept.

For now we will create three Container Definitions. They are defined by the NinjaInventoryContainerDataAsset, so all these new Data Assets should be created using that class as the base.

First the Backpack container. This is marked as the default container in the inventory, using the Inventory.Container.Default tag. This tag will be reference later on when we configure our Inventory Layout.

Backpack Container

We want to allow any items to be placed in the backpack, so our Item Filter Compatibility should be configured as such. Backpack Query

Then the Primary Container A, which is going to be our main hand, for the primary loadout. Primary Container A

This container should be more restrictive, only allowing items tagged as weapons. So our Item Filter Compatibility should reflect this.

Then the Primary Container A, which is going to be our main hand, for the primary loadout. Primary Query

And finally the Primary Container B, which is going to be our off hand, for the primary loadout. This should be as restrictive as the other Primary Container, so we can use the same Item Compatibility Query for this.

Primary Container B

The following table describes each property available in the container definition.

Property Description
Display Name Name used to represent this container in the UI. Can be typed-in or retrieved from a String Table.
Gameplay Tags Any tags used to represent this container. Usually an identifying tag, plus any additional traits.
Container Class The class used to represent this container when added to an inventory.
Default State Tag Used when containers represent Equipment Containers, indicates the default equipment state.
Priority Priority used to decide where an item should be added. Lower numbers represent higher priority.
Slots Amount of storage slots available in this container. Equipment Containers can only have one storage slot.
Slots Attribute A Gameplay Attribute that represents the amount of slots. If set, takes priority over the "Slots" parameter.
Item Compatibility Query A gameplay tag query used to verify that an item is compatible with this container.

Create the Inventory Layout

Now that some containers were created we need to define the actual structure which is established by an Inventory Layout.

You can create many layouts for different types of inventory. For example, players can have an elaborate layout with many equipment slots, pockets and backpacks, while enemies can have a single loot container and maybe nothing else. The point here is that all these layouts can reuse the containers that were created on the previous step.

In any case, an Inventory Layout is defined by the NinjaInventoryLayoutDataAsset, so let's create a new Data Asset from that class and start working on it. We need to assign all our relevant containers to this layout.

Inventory Layout

In the Layout we also need to define a query that helps the system to identify which container is the default one. Notice that we have the Inventory.Container.Default here, matching the tag added to our Backpack Container.

Inventory Layout Query

The following table describes each property available in the layout definition.

Property Description
Display Name Name used to represent this container in the UI. Can be typed-in or retrieved from a String Table.
Default Container Query A gameplay tag query used to determine the default container in this inventory.
Containers All containers assigned to the layout.

Configure the Inventory Manager

With a proper Inventory Layout, we are ready to assign it to the Inventory Manager. There are three options for you to set the layout to an Inventory Manager:

  1. Via the GetInventoryLayout in the InventoryManagerProviderInterface, implemented in the Player State.
  2. Via the GetInventoryLayout in the InventoryManagerProviderInterface, implemented in the Player Pawn or Character.
  3. Directly to the Inventory Manager Component, setting the InventoryLayout property.

For this example, we'll simply set our Inventory Layout to the Player State's Inventory Manager.