Ninja Bear Studio Plugins Help

Set up the Inventory Manager and add your items

This how-to will show how to configure your Inventory Manager component, including the interface implementation. Since this guide focus on preparing the Player Character, the component will be added to the Player State.

Before starting, please make sure that:

  1. The project has a Player State, and it is assigned to the Game Mode.

  2. The Gameplay Ability System is configured, and it has the Inventory Attribute Set initialized, including the Backpack Attribute.

  3. The Gameplay Debugger is configured, including the Inventory Category.

Add the Inventory Manager Component

  1. Add the Inventory Manager component to your Player State.

    In Blueprints, go to your Components, search for Inventory and add Ninja Inventory Manager Component.


    Add the Inventory Manager Component

    Create a variable for the of UNinjaInventoryManagerComponent in your class.


    #pragma once #include "CoreMinimal.h" #include "GameFramework/PlayerState.h" #include "PluginLabsPlayerState.generated.h" class UNinjaInventoryManagerComponent; UCLASS() class PLUGINLABS_API APluginLabsPlayerState : public APlayerState { GENERATED_BODY() public: APluginLabsPlayerState(const FObjectInitializer& ObjectInitializer = FObjectInitializer::Get()); private: /** Hard reference to the Inventory Manager Component used by the player. */ UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Components", meta = (AllowPrivateAccess = true)) TObjectPtr<UNinjaInventoryManagerComponent> InventoryManagerComponent; };

    Create an instance of UNinjaInventoryManagerComponent in your constructor.


    #include "GameFramework/PluginLabsPlayerState.h" #include "Components/NinjaInventoryManagerComponent.h" APluginLabsPlayerState::APluginLabsPlayerState(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) { static const FName InventoryComponentName = TEXT("InventoryManager"); InventoryManagerComponent = CreateOptionalDefaultSubobject<UNinjaInventoryManagerComponent>(InventoryComponentName); }
  2. Add the Inventory Manager Provider Interface to your Player State.

    Open your Class Settings, navigate to the list of Implemented Interfaces and add the interface.


    Add the Inventory Manager Component

    In the My Blueprint panel, under Interfaces, expand Inventory Manager Provider and double-click Get Inventory Manager.

    In the Blueprint Graph, drag your Inventory Manager into the Return Value.


    Add the Inventory Manager Component

    Add IInventoryManagerProviderInterface to your class declaration, and override GetInventoryManager.


    #pragma once #include "CoreMinimal.h" #include "GameFramework/PlayerState.h" #include "Interfaces/InventoryManagerProviderInterface.h" #include "APluginLabsPlayerState.generated.h" class UNinjaInventoryManagerComponent; UCLASS() class PLUGINLABS_API APluginLabsPlayerState : public APlayerState, public IInventoryManagerProviderInterface { GENERATED_BODY() public: APluginLabsPlayerState(const FObjectInitializer& ObjectInitializer = FObjectInitializer::Get()); // -- Begin Inventory Provider implementation virtual UNinjaInventoryManagerComponent* GetInventoryManager_Implementation() const override; // -- End Inventory Provider implementation private: /** Hard reference to the Inventory Manager Component used by the player. */ UPROPERTY(EditDefaultsOnly, BlueprintReadOnly, Category = "Components", meta = (AllowPrivateAccess = true)) TObjectPtr<UNinjaInventoryManagerComponent> InventoryManagerComponent; };

    Implement GetInventoryManager, so it returns the Inventory Manager.


    #include "GameFramework/PluginLabsPlayerState.h" #include "Components/NinjaInventoryManagerComponent.h" APluginLabsPlayerState::APluginLabsPlayerState(const FObjectInitializer& ObjectInitializer) : Super(ObjectInitializer) { static const FName InventoryComponentName = TEXT("InventoryManager"); InventoryManagerComponent = CreateOptionalDefaultSubobject<UNinjaInventoryManagerComponent>(InventoryComponentName); } UNinjaInventoryManagerComponent* APluginLabsPlayerState::GetInventoryManager_Implementation() const { return InventoryManagerComponent; }

Add Default Items

  1. Navigate to the Inventory Manager in the Player State.

  2. In the Defaults Panel, go to the Inventory Manager category and set the Layout_Player as the Inventory Layout.

  3. Add a new entry to the Default Items property, select Weapon_Sword as the Item Data.

  4. Add another entry to the Default Items property, select Weapon_Shield as the Item Data.

  5. Add one more entry to the Default Items property, select Resource_IronBar as the Item Data.

  6. For the Resource_IronBar, add a new Fragment Memory, select the Stack fragment class along with the Stack Memory. Set the Stack Size to 50. This will initialize default values for the Stack Fragment present in the Iron Bar Definition.

  7. Ensure that your configuration is similar to this.

    Adding defaults items to the Inventory Manager

Check your Inventory in the Gameplay Debugger

  1. Hit Play, open the Gameplay Debugger and activate the Inventory category.

  2. Confirm that the Sword and Shield were assigned to their Preferred Containers.

    Confirm that three stacks of Iron Bars were created: two stacks with a size of 20, one stack with a size of 10. They occupy positions 0, 1 and 2 in the Backpack. This indicates that the stack was properly distributed following its configuration.

    Items and Containers in the Gameplay Debugger
Last modified: 11 August 2024