First Person Exploration Kit: Inventory Items and Inventory Consumers Overview



Inventory Items

The FPEInteractableInventoryItemScript component provides the means to create Inventory Items that the player can collect and use in a variety of ways.


Table of Contents


Overview

Inventory Items are similar to Pickup items, but they have some special properties. Most notably, they can be stored in inventory, then later retrieved by the player for interactions like unlocking doors, solving puzzles, etc.

The included FPEGameMenu has an Items tab, which shows how you can display and interact with stored inventory items. Clicking on an item in the inventory screen will display its actions.


Creating an Inventory Item

  1. Add a mesh or other visual object (e.g. a Cube) to your scene
  2. Add a primitive collider (e.g. Box Collider)
  3. Add the FPEInteractableInventoryItemScript component (script) to the cube

  4. Note: This will automatically add a RigidBody and AudioSource to your object.

  5. Open the FPEInventoryManagerScript file and add a new Inventory Type to the eInventoryItems enum as shown below



  6. Add a new lookup value inside the FPEObjectTypeLookup script, as shown below. This will ensure that the Save/Load system knows which prefab corresponds to which Inventory type.



  7. In the Inspector, scroll down to the Inventory section, and assign the following values:



  8. Inventory Item Type The type you created in the eInventoryItems enum above (e.g. APPLE, MY_CUSTOM_INV_A, etc.)
    Inventory Quantity The number of the type to give the player when they store this inventory item. For example, a Battery prefab might have a quantity of 1 of type BATTERY, while a BoxOfBandages prefab might have a quantity of 12 of type BANDAGE.
    Inventory Get Sound (Optional)If specified, this sound will override the default inventory get sound.
    Can Be HeldIf true, the player can take this item out of their inventory and hold it in their hand.
    Can Be DroppedIf true, the player can drop this item from their inventory.
    Can Be ConsumedIf true, the player can consume this inventory item. This requires an Inventory Consumer
    Item NameThe friendly display name of the item. E.g. demoApple has an Item Name of 'Apple'
    Item ImageThe image shown in the inventory screen along with Name and Description. Refer to "inventoryItemImageTemplate.psd" Photoshop template inside the FirstPersonExplorationKit/Textures/Templates/ folder. You can create consistent images using the provided InventoryImageCapture.unity Scene file in the FirstPersonExplorationKit/Scenes/Utility/ folder.
    Item DescriptionThe long form description of the item. E.g. demoApple description is 'It's an apple. Looks crunchy!'
    StackableIf true, the item will be stacked inside the player's inventory. This means that the player can have more than one of this item and it will only take up one slot. The true quantity will be displayed in the top right (e.g. 5 items will have a label of 'x5')

  9. To save your new Inventory Item prefab, put it in your Resources/InventoryItems/ folder



  10. You are finished creating a custom Inventory Item prefab, hooray! If you are stuck, or getting weird errors, please email support@whilefun.com.




Inventory Consumers

Inventory Consumers (FPEInventoryConsumer), such as the included DemoInventoryConsumer, are scripts that make things happen when the associated inventory item is consumed. For example, the demoApple prefab, or inventory type APPLE, uses the DemoInventoryConsumer, which is assigned as a component in the Inspector:

Inventory Consumer

All Inventory Consumers must implement and override the consumeItem() function, with a call to base.consumeItem() as shown below.

Demo Inventory Consumer

When your inventory item is consumed, the consumer functionality kicks in and the consumeItem() function is ultimately called, resulting in the execution of your custom consumer code.


Inventory Ideas - Combining Actions