Skip to content

Containers and Layouts

Containers and Layouts are the foundation of an Inventory. They define all available parts of the inventory that can contain items and specific traits about these parts.

Inventory Containers

Summary: Inventory Containers
  • Containers can represent a Region, an Equipment Slot or an actual Container.
  • Containers are defined by a Container Definition and represented by a Container Instance.
  • They can have traits defined via Gameplay Tags.
  • Container Definitions are created from the NinjaInventoryContainerDataAsset.
  • Containers are stored using the base class NinjaInventoryContainer.
  • You can create your own container instance for a specific purpose, or globally via settings.

There are many names that can be used to exemplify a container such as a Region for items, a Slot that can hold equipment pieces, actual containers representing items inside the inventory and so on. They are a very light, very simple entity that represents parts of an inventory.

Containers are defined via the Primary Data Asset NinjaInventoryContainerDataAsset. This is where you can assign Gameplay Tags to fine-tune the purpose or other traits of a specific Container, and also determine which Container Class, that represents the Container once it has been assigned to an Inventory Manager. The default class used is NinjaInventoryContainer.

You can fine-tune a specific container's behavior by extending its base class and assigning it to the definition. You can also redefine the base class globaly, in the Inventory Settings page.

Here's a summary of all properties available in a Container Definition

Property Description
Display Name Localized name for this container.
Gameplay Tags Gameplay Tags defining additional traits to this container.
Container Class Class used to create intances of Containers.
Priority Priority applied when matched against other Container.
Slots Maximum amount of item slots available to this container.
Slots Attribute Overrides the Slots property, using a Gameplay Attribute instead.
Item Compatibility Query Query applied to all items before adding them, to ensure they are compatible.

Inventory Layouts

Summary: Inventory Layouts
  • Layout Data Assets are created from the UNinjaInventoryLayoutDataAsset.
  • Determines all containers initially available to an Inventory Manager
  • Provides an important query to inform which container is the default one.
  • It's recommended that you only have one default container per inventory.
  • Can be assigned in many ways. Once assigned, layouts cannot be changed.

Containers are grouped and assigned to an Inventory Manager via an Inventory Layout, which is a Data Asset that can be created from UNinjaInventoryLayoutDataAsset. There are a few relevant pieces of information that can be defined in this data asset.

First, and most importantly, you can assigned all containers that will be initially available to an Inventory Manager. Items can only be added to containers available to the Manager. You can eventually add and remove containers from the Inventory Manager, but if you are planning to have default items, then you must assign all default containers.

In the Layout, you must also define your default container. By default, any Container tagged with Inventory.Container.Default will be considered the default container. It's highly recommended that you only keep one default container in an inventory at all times.

You can assign a Layout to an Inventory Manager using a few different ways.

Assignment Description
Property Directly to an Inventory Manager, via it's InventoryLayout property.
Interface, Owner Via the InventoryManagerProviderInterface in the Inventory Manager's owner.
Interface, Avatar Via the InventoryManagerProviderInterface in the Inventory Manager's avatar.

If multiple strategies are used, they are prioritized in the following order: Property > Interface implemented in the Owner > Interface implemented in the Avatar.