Configure the Inventory
Last modified: 29 December 2024To create our secondary weapon, we should have Ninja Inventory configured. So this is our next task: perform the setup, update the Weapon Manager, and convert our weapons into Items and Equipment.
Add the Inventory Attribute Set
Create a Data Table for Inventory Attributes, using the base data from Gameplay Attributes.
Change the initial Backpack Attribute to
20
, or any other value that you prefer.Add the Inventory Attribute Set to the player, via the Ability Definition.
Add the Equipment Manager Component to the Player Character.
Implement the Equipment Provider Interface to the Player Character and implement the
GetEquipmentManager
function.In the Equipment Manager, create two virtual slots for the weapon actors, one for the sword, one for the shield.
These Slots will be identified by the Gameplay Tags
Equipment.Slot.Weapon.MainHand
andEquipment.Slot.Weapon.OffHand
. In this example they are mapped tosWeaponMainHand
andsWeaponOffHand
sockets.tip
Slot/Socket Mapping
Since our weapons are Actors, they are directly attached to the character. We need to map Slots to the Sockets previously created for the original Weapon Manager.
For more information about the Slot/Socket Mapping, please check the Equipment page.
Re-parent your base Weapon Class or Blueprint to
ANinjaCombatEquipmentWeaponActor
.Add the
EquipmentActorInterface
to the base class. You do not need to implement any methods from this interface.Create a new Equipment Definition, from the Content Menu, for the Sword and Shield. Be sure to create this Data Asset in the folder configured in the Asset Manager.
Add a new State Configuration for the
Equipment.State.Activated
state. These instructions will be used when the Equipment is ActiveAdd an Actor entry setting the Sword Actor as the Actor Class, and the
Equipment.Slot.Weapon.MainHand
as the Slot Tag.Add an Actor entry setting the Shield Actor as the Actor Class, and the
Equipment.Slot.Weapon.OffHand
as the Slot Tag.

tip
Scene Component Selector
For a regular character, you can use the Character Mesh selector, or even setting a Gameplay Tag to find another Scene Component.
For more complex characters, using something like realtime IK Retargeting or multiple possible meshes from a Leader Pose Component, you might want to use the Provider Interface selector.
More information about these selectors can be found in the Equipment page.
Create a new Item Definition, from the Content Menu, for the Sword and Shield.
Set a Gameplay Tag that identifies this item -
Inventory.Item.Weapon.SwordAndShield
.Add the User Interface Fragment, set the Display Name (" Sword and Shield"), Display Type (Weapon) and an Icon.
Add the Stack Fragment, set the Stack Limit as 1 and Maximum Limit as 1.
Add the Container Fragment, set the Preferred Container Query to indicate the Weapon Container.
Add the Equipment Fragment, set the Equipment Definition defined in the previous step as the Equipment Data.

Create a new Container Definition, from the Content Menu, for the Backpack container.
Set the Display Name as Backpack, and add
Inventory.Container.Backpack
andInventory.Container.Default
Gameplay Tags.tip
Default Container
The
Inventory.Container.Default
is provided by the system and indicates a default container, used when no better option is available.Set the Priority to
100
, so this container will have low priority in comparison with other compatible containers.Set the
NinjaInventoryAttributeSet.BackpackSlots
as the Slots Attribute.tip
Backpack Attribute Value
This attribute is part of the Ninja Inventory Attribute Set, and it was previously initialized in this guide.

Create a new Container Definition, from the Content Menu, for the Primary Weapon.
Set the Display Name as Primary Weapon, and add
Inventory.Container.Equipment
andInventory.Container.Weapon.Primary
Gameplay Tags.tip
Equipment Container
The
Inventory.Container.Equipment
is provided by the system and indicates an equipment slot, used to store equipment instances.Containers configured as Equipment Slots will default their size to 1.
Set
Equipment.State.Activated
as the Default State Tag, defining the initial state of equipment instances added to this slot.Set the Item Compatibility Query so it filters items tagged as Weapons.

Create a new Container Definition, from the Content Menu, for the Secondary Weapon.
Repeat the steps above, defining the Secondary Weapon slot, setting
Inventory.Container.Weapon.Secondary
, as the identifying Gameplay Tag.Set the Default State Tag to
Equipment.State.Deactivated
so items are deactivated by default.Set the Priority to
2
to prioritize the Primary Weapon equipment slot.

Make sure that Ninja Inventory is added to your project and your Asset Manager was configured, as instructed by the Setup page.
Create a Player State using
NinjaGASPlayerState
as the base class (or a subclass of it). Set it to your Game Modetip
You probably have a Player State already configured, from the GAS setup guide.
Add the Inventory Manager Component to the Player State.
Add the Inventory Provider Interface to the Player State and implement the
GetInventoryManager
function.
In the Inventory Manager Component, set the Inventory Layout that was just created.
Add an entry for Default Items and add the Sword and Shield as the Item Data.
tip
Automatic Slot Placement
The Weapon Slot and Weapon Item are configured so this item will be automatically placed in the correct equipment slot.

Press Play and check the sword and shield added to the correct slots and sockets.
Open your Gameplay Debugger, by pressing the pre-defined key. You can access the Gameplay Debugger Configuration in the Project Settings, Gameplay Debugger page.
Expand the Inventory Category and notice that both Containers were added and the Weapon Item is set to the correct slot.
