Inventory Pro Add-On Documentation
  • Welcome to Inventory Pro Add-On for FPS Engine!
  • BEFORE WE START
    • Early Considerations
    • Add-On Compatibility
    • List of Tutorials
  • GETTING STARTED
    • 01. Basic Set-Up
    • 02. Roadmap
  • CONTENT
    • 03. Content
      • 03.1 CRAFTING
        • Recipe_SO
          • Ingredient
        • CraftingButton
        • CraftingProcess
        • CraftingUI
        • CraftingBench
        • IngredientUIIcon
      • 03.2 FAV MENU
        • FavItemSlot
        • FavItemsMenu
          • FavItemReference
      • 03.3 INTERACTABLES
        • InventoryItemPickeable
      • 03.4 INVENTORY
        • InventoryGridData_SO
        • InventoryProManager
        • GridGenerator
        • InventorySlot
        • SlotData
        • InventoryProManagerInputActions
      • 03.5 ITEMS
        • AppleItem_SO
        • EnergyDrinkItem_SO
      • 03.6 OTHERS
        • 03.6.1 TRADE HUB
          • TradeButton
          • TradeUI
          • TradeHub
        • Chest
        • ExamineItem
      • 03.7 SHOP
        • PurchasableItem
        • Shop
          • ShopItemData
        • ShopUI
        • ShopButton
      • 03.8 UI TOOLKIT
        • ContextMenu
        • HighlightInteractions
        • Padding
        • TooltipManager
    • 04. Shared Content for Add-Ons
  • HOW TO USE & GUIDES
    • Uninstalling the Add-On: Fixing Errors
    • Creating, Updating & Deleting Recipes
    • Inventory Designer: Creating, Updating & Deleting Inventory Grid Data
    • Working with Crafting Benches
    • Working with Chests
    • Working with Shops
    • Working with Purchasable Items
    • Working with Item Examination
    • Favorite Pinned Items Menu Considerations
    • Inventory, Hotbar & Chests Considerations
    • Tetris Inventory Considerations
    • Weapons & Ammo from the Inventory
    • Custom Item_SOs
    • Adding a New Inventory
  • FAQ
    • FAQ
  • SUPPORT
    • Support
Powered by GitBook
On this page
  1. HOW TO USE & GUIDES

Custom Item_SOs

PreviousWeapons & Ammo from the InventoryNextAdding a New Inventory

Last updated 1 month ago

If you are looking for examples of Implementations, check and .

Item_SO can be extended to create various types of items with custom behaviors and abilities triggered upon use. If your item does not require any custom behavior or is not intended to be used, there's no need to extend Item_SO.

For example, heals the player when used. To implement this functionality, it extends Item_SO and overrides the Use method.

Create a Custom Item_SO & Use Behaviour

For this guide, let´s imagine that we´re adding a potion that increases the heal we receive.

1

Create a New Script

First, we´ll need to create a new script. For organization & clarity purposes, we´ll call this C# script PotionItem_SO. Since this script will inherit from Item_SO, it´s highly recommended to follow the naming convention: NameItem_SO

using cowsins;
using UnityEngine;

[CreateAssetMenu(fileName = "newPotionInventoryItem", menuName = "COWSINS/Inventory/Showcase Items/New Potion")]
public class AppleItem_SO : Item_SO
{
    public float healMultiplierToAdd = .1f;
}

You can copy & paste this code, and adjust it to fit your custom Item_SO.

Because of the [CreateAssetMenu] Attribute, you´ll be able to create an instance of this Item_SO in your Project folder by right clicking > Create > Cowsins > Inventory > Showcase Items > Your Item

2

Implement the Use Method / Behaviour

Now, we´ll need to make a custom Use method, so whenever we use this Item from the Inventory or Fav Pinned Menu, custom behaviour will be run.

For that, we´ll need to override the base Use method.

public override void Use(InventoryProManager inventoryProManager, InventorySlot slot)
{
    base.Use(inventoryProManager, slot);
}

Notice how you have access to the InventoryProManager and the InventorySlot from which the Item has been used.

For this specific example, we´ll implement the Heal Multiplier logic:

public override void Use(InventoryProManager inventoryProManager, InventorySlot slot)
{
   // Access PlayerMultiplier reference
   PlayerMultipliers multiplier = inventoryProManager._WeaponController.GetComponent<PlayerMultipliers>();
   // Increases Heal Multiplier
   multiplier.healMultiplier += healMultiplierToAdd;
   // base.Use ensures the item is consumed.
   base.Use(inventoryProManager, slot);
}
3

Final Script

using cowsins;
using UnityEngine;

[CreateAssetMenu(fileName = "newPotionInventoryItem", menuName = "COWSINS/Inventory/Showcase Items/New Potion")]
public class AppleItem_SO : Item_SO
{
    public float healMultiplierToAdd = .1f;
    
    public override void Use(InventoryProManager inventoryProManager, InventorySlot slot)
   {
      // Access PlayerMultiplier reference
      PlayerMultipliers multiplier = inventoryProManager._WeaponController.GetComponent<PlayerMultipliers>();
      // Increases Heal Multiplier
      multiplier.healMultiplier += healMultiplierToAdd;
      // base.Use ensures the item is consumed.
      base.Use(inventoryProManager, slot);
   }
}
using cowsins;
using UnityEngine;

[CreateAssetMenu(fileName = "newInventoryItem", menuName = "COWSINS/Inventory/Showcase Items/New Item")]
public class ItemNametem_SO : Item_SO
{
    // Your variables go here.
    
   public override void Use(InventoryProManager inventoryProManager, InventorySlot slot)
   {
      // Custom Use Logic goes here.
      base.Use(inventoryProManager, slot);
   }
}

AppleItem_SO
EnergyDrinkItem_SO
AppleItem_SO