Skip to content

Initial Setup

Installing the Ninja Inventory plugin requires a few steps but should be quite straightforward.

Summary: Initial Setup
  • Download the plugin from the Unreal Marketplace and enable it in your project.
  • Optionally move it to your project's /Plugins folder.
  • Optionally add the C++ modules to your .Build.cs file.
  • Assign the NinjaInventoryAttributeSet to your character and initialize the appropriate attributes.
  • Register the necessary Primary Assets to your Asset Manager.
  • Add the Inventory Manager Component to your Player State and implement the appropriate interface.
  • Add the Equipment Manager Component to your Avatar and implement the appropriate interface.
  • If you plan on using Item Qualities, create and set the Item Quality Data Table.

Installation

  1. Download the plugin from the Epic Launcher.
  2. Enable the plugin in your project.
  3. Restart the Engine when requested.

Optionally move the plugin into your project

Since the Epic Launcher may automatically download updates, it's recommended that you move the plugin into your project's /Plugins folder and then remove the version installed in the engine, using the launcher.

C++ Modules

If you plan to use system classes in C++, then make sure to add the appropriate modules to your Build.cs file.

public MyGame(ReadOnlyTargetRules target) : base(target)
{
    PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
    PublicDependencyModuleNames.AddRange(new []
    {
        // ...
        "GameplayAbilities",
        "GameplayTags",
        "GameplayTasks",
        "NinjaInventory",
        "NinjaInventoryEquipment",
        "NinjaInventoryGameplay",
        "NinjaInventoryUI",
        "StructUtils",
        // ...
    });
}

Ability System

The Inventory Framework uses the Gameplay Ability System to perform certain tasks, represented by Gameplay Abilities. The system also uses an Attribute Set to determine overall data such as wealth, encumbrance and equipment level, along with the Gameplay Effects to modify them.

This means you will need to configure the Gameplay Ability System in your project before moving on to the Inventory System.

  1. Your Pawn must provide access the Ability System Component via the AbilitySystemInterface. It does not matter where the Ability Component actually is, so you can decide between the Pawn or the Player State.

  2. If you want to use the default Inventory Attributes, then add the NinjaInventoryAttributeSet to your pawn as well. The WeightLimit Attribute is the only one that could need initialization. You are free to initialize the Wealth Attribute too. If you want to know more about the Attribute Set and included Attributes, please check the Attribute Reference.

  3. For now, we won't add any Gameplay Abilities as we'll have to configure them later on and they won't be necessary anyway during the first few steps with the system.

C++ Only

Unfortunately, the Gameplay Ability System does not provide a way to add Attribute Sets to your character using Blueprints. If you are uncomfortable with C++, you can look into an external plugin, like the GAS Companion.

Data Assets

Register the following assets in your Asset Manager Configuration:

  1. UNinjaInventoryContainerDataAsset
  2. UNinjaInventoryItemDataAsset
  3. UNinjaEquipmentDataAsset
  4. UNinjaEquipmentSlotDataAsset

Folder Locations

Make sure to set the appropriate directories where your assets will be located in your game. In these examples, the assets are located in the following folders: Data/Inventory/Items and Data/Inventory/Equipment.

Primary Assets

[/Script/Engine.AssetManagerSettings]
+PrimaryAssetTypesToScan=(PrimaryAssetType="InventoryContainerData",AssetBaseClass="/Script/NinjaInventory.NinjaInventoryContainerDataAsset",bHasBlueprintClasses=False,bIsEditorOnly=False,Directories=((Path="/Game/Data/Inventory/Containers")),SpecificAssets=,Rules=(Priority=-1,ChunkId=-1,bApplyRecursively=True,CookRule=Unknown))    
+PrimaryAssetTypesToScan=(PrimaryAssetType="InventoryItemData",AssetBaseClass="/Script/NinjaInventory.NinjaInventoryItemDataAsset",bHasBlueprintClasses=False,bIsEditorOnly=False,Directories=((Path="/Game/Data/Inventory/Items")),SpecificAssets=,Rules=(Priority=-1,ChunkId=-1,bApplyRecursively=True,CookRule=Unknown))
+PrimaryAssetTypesToScan=(PrimaryAssetType="EquipmentData",AssetBaseClass="/Script/NinjaInventoryEquipment.NinjaEquipmentDataAsset",bHasBlueprintClasses=False,bIsEditorOnly=False,Directories=((Path="/Game/Data/Inventory/Equipment")),SpecificAssets=,Rules=(Priority=-1,ChunkId=-1,bApplyRecursively=True,CookRule=Unknown))
+PrimaryAssetTypesToScan=(PrimaryAssetType="EquipmentSlotData",AssetBaseClass="/Script/NinjaInventoryEquipment.NinjaEquipmentSlotDataAsset",bHasBlueprintClasses=False,bIsEditorOnly=False,Directories=((Path="/Game/Data/Inventory/Equipment")),SpecificAssets=,Rules=(Priority=-1,ChunkId=-1,bApplyRecursively=True,CookRule=Unknown))

Inventory Manager

The Inventory Manager Component must be added to your Pawn or Player State, depending on how persistent you need your inventory items to be, related to player respawns. Generally, you would have it in the same location as your Ability System Component.

Add the NinjaInventoryManagerComponent to the proper actor, Pawn/Character or Player State and add the InventoryManagerProviderInterface. We'll talk about this interface in more details later on, but for now, just implement the GetInventoryManager function, providing the Inventory Manager Component that you just added.

Player State Header:

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/PlayerState.h"
#include "Interfaces/InventoryManagerProviderInterface.h"
#include "NinjaFrameworkPlayerState.generated.h"

class UNinjaInventoryManagerComponent;

UCLASS()
class NINJAFRAMEWORK_API ANinjaFrameworkPlayerState : public APlayerState public IInventoryManagerProviderInterface
{   

    GENERATED_BODY()

public:

    ANinjaFrameworkPlayerState(const FObjectInitializer& ObjectInitializer = FObjectInitializer::Get());

    // -- Begin Inventory System implementation
    virtual UNinjaInventoryManagerComponent* GetInventoryManager_Implementation() const override;
    // -- End Inventory System implementation

private:

    /** Hard reference to the Inventory Manager Component used by the player. */
    UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Components", meta = (AllowPrivateAccess = true))
    TObjectPtr<UNinjaInventoryManagerComponent> InventoryManagerComponent;

};

Player State Implementation:

#include "GameFramework/NinjaFrameworkPlayerState.h"
#include "Components/NinjaInventoryManagerComponent.h"

ANinjaFrameworkPlayerState::ANinjaFrameworkPlayerState(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer)
{
    bReplicates = true;
    MinNetUpdateFrequency = 33.f;
    NetUpdateFrequency = 66.f;
    NetPriority = 3.f;
    InventoryManagerComponent = CreateOptionalDefaultSubobject<UNinjaInventoryManagerComponent>("InventoryManager");    
}

UNinjaInventoryManagerComponent* ANinjaFrameworkPlayerState::GetInventoryManager_Implementation() const
{
    return InventoryManagerComponent;
}

Pawn or Player State?

While deciding where to add your Inventory Manager to the Pawn or Player State, you should consider how persistent the inventory should be.

If the inventory persists over respawns or server travels, a Player State is a good choice. Otherwise, if the inventory is not persistent or it has a small lifespan (i.e. AI Enemies), the Pawn is more appropriate.

Equipment Manager

The Equipment Manager is always added to the actual pawn or character, also know as the "Inventory Avatar".

Add the NinjaEquipmentManagerComponent to the proper actor and add the EquipmentManagerProviderInterface and implement the GetEquipmentManager function, providing the Equipment Manager component that you just added.

Quality Table

If you plan on adding qualities to your items, such as Common, Rare, Epic and so on, then you need to define these global qualities in a Data Table.

First, create a new Data Table based on the FInventoryItemQualityMappingTableRow struct and add each supported quality to this table. Each row will have the following properties:

Property Description
Quality Tag A Gameplay Tag that uniquely represents this quality.
Quality Text Text that represents this quality in the UI. Supports localization.
Quality Color A color that represents this quality when used in the UI.

Once your Quality Table is complete, you can assign it in your Project Settings, under the Ninja Inventory page.