The Ultimate Inventory System is a very flexible system allow you to create any type of inventory. Usually the more a framework is flexible the harder it is to use and understand. The Ultimate Inventory System is structured in a way to make it as easy to understand as possible. To do this the system includes a workflow with some rules and streamlines the items should be created. There are many components in the system and they each play a key part:
Attributes are used throughout the system. Attributes are allowed to override, inherit or modify the value of another attribute. Attributes are used to create variants of Item Definitions and speeds up iteration time.
The three variant types are:
- Override: Overrides the parent attribute value.
- Inherit: Inherits the parent attribute value.
- Modify: Uses an expression to compute a value that is dependent on the “parent” attribute or any other attribute in the same collection.
Example myAttribute2 = “[myAttriute1] * 20 + <Inherit>”
Modify is extremely powerful when it comes to speeding up iteration time. It also gives the ability for non-programmers to have simple logic on their items. Item Actions should be used for more complex equations.
- Parent -> child
- HealAmount: 5 -> HealAmount (override 10): 10
- HealAmount: 5 -> HealAmount (inherit): 5
- HealAmount: 5 -> HealAmount (modify “<Inherit>*3”): 15
Item Categories are used to structure your items in a sensible way. All items of a certain category will have the same attributes, with varying values. This ensures that the same action can be performed on any items that are part of the same category. Categories can be nested and parented with multiple children and parents. Mutable categories will set all of the child items to mutable which mean that the attribute values can change at runtime.
- Weapon : Equippable
- OneHandedWeapon : Weapon, OneHanded
- Dagger: OneHandedWeapon
- Sword: OneHandedWeapon
Item Definitions can be thought of as templates or molds for items. Item Definitions can have attributes that are consistent across all items created from it. It also contains a reference to a “Default Item” which is used as a base to create the other item instances.
- No Parent -> HealPotion (HealAmount: 10, CoolDown: 2)
- HealPotion -> SmallHealPotion (HealAmount (Override 6): 6, CoolDown (Inherit): 2)
- HealPotion -> BigHealPotion (HealAmount (Modify “<Inherit>*2.5”): 25,
CoolDown (Override 3): 3)
Items are created at runtime and contain attribute values that can be unique to that Item. Even though two Items have the same mold (Item Definition) they can be set to be slightly different. If the Item is part of a mutable Item Category it is even possible to change the values of the Item attributes at runtime.
Items do not have any “item specific logic” attached to it. It is meant to be a simple set of data. Using that data, which consists of the Item Category, Item Definition and Item attributes, the system knows what kind of actions can be performed on them.
Items can be mutable or immutable. Mutable items can be changed at runtime, whereas immutable items cannot be.
Item Actions contain logic that can be performed on some Items of a certain category. A simple example is a “Consume” action which can be performed on any item of a “Consumable” category. Or an “Equip” action that could be performed on any “Equippable” items. These actions are game specific, with examples of use cases in the demo. The Item Actions are meant to be expanded upon in order to take full advantage of.
Item Object is a MonoBehaviour which binds an Item to a GameObject. This is useful for Items that can be equipped, picked up/ dropped or simply that need a presence in the scene.
Item Object Behaviour
Item Object Behaviours are components which allow attaching logic to an Item Object. For example using a “Sword” to attack or a “Gun” to fire, reload, etc… Having a presence in the scene lets you check for trigger/collision events or spawn projectiles from the point of the gun’s barrel.
Currency is an abstract object which can be used to exchange with other objects.
A Crafting Recipe contains the input and outputs for combining one or more objects into a new item. The Crafting Recipe works with the Crafting Processor in order to perform the logic to covert one set of objects into another.
An Inventory is a group of Item Collections. An Item Collection can have any restrictions on the items that go in or out. Splitting the inventory in different chunks is a good way to organize it. For example, having two Item Collections, one for the equipped Items and another for the non-equipped Items is a common organizational structure.
Item Collections contain a set of Items. Items are stored in a collection as a list of Item Stacks. The Item Collection sends events to the Inventory when Items are added, removed, etc…
An Item Stack is an object that stores an amount of an item amount. An example of an Item Stack is “5 apples”. Item Stacks should only exist within an Item Collection. It should not be confused with an Item Amount which can exist outside of the collection.
An Item Amount is a simple structure with an Item and an amount. It should not be confused with an Item Stack which requires an Item Collection.
Item Info gives more specification about the items and where they came from. For example imagine you have an Inventory with 2 Item Stacks:
- Stack 1:”5 apples”
- Stack 2:”10 apples”
Where apple is an immutable Item. If you wish to remove 3 apples from Stack 2 you can specify an Item Info as such. When adding Items to an Item Collection you may also specify where the Item came from and in which Item Stack it should be added to.
An Item Slot is simply a name and an Item Category. It is used to define what type of Item can be added in that slot. It is used by the Item Slot Set for equipping items with an Equipper or setting up an Item Slot Collection.
An Item View is used to display an item is the UI, it uses Item View Modules to customize exactly how the item shows up.
Item View Slot
An Item View Slot is used in the UI to detect interactions such as select, click, drag, drop and more. It usually contains an Item View.
Inventory System Database
This is an asset that is created in the editor and it is used to store all your Item Categories, Item Definitions, Currencies, Crafting Categories and Crafting Recipes for your project. These objects are referred to as Inventory System Objects. The database is simply a container of data and is loaded in the Inventory System Manager at the start of a game.
Inventory System Manager
The Inventory system Manager is very important as it manages every Item, Item Definition, Item Category, Currency, Crafting Category and Crafting Recipe in your project. When the project starts it will load the Inventory System Database and it will get references from any of the registered inventory system objects.
The Inventory System Manager ensures only valid objects are registered and also provides a convenient method to look up objects based on an ID or name. The Inventory System Manager is also used to create Items at runtime.