The item system is a generic implementation allowing for a wide variety of uses. Items are any object that the character can carry, such as an assault rifle, sword, bow, grenade, shield, flashlight, or book. When a new item is built it is placed under the Item GameObject which is a child of the character.
An item is identified by the Item Definition ScriptableObject. This Item Definition must be unique for each slot and is purely a representation of the item GameObject that should be interacted with. Item Definitions allow you to easily reference which item should be picked up within the ItemPickup component, or which item should be used by the Use ability. Each item GameObject is required to have the Item component and this component implements the logic for more general item-related functions such as initialization, being picked up, equipped, dropped, etc.
The object that is actually held by the character and rendered on the screen is managed by the Item Perspective component. A First Person Item Perspective and a Third Person Item Perspective component should be added to the item GameObject depending on which perspective the item will be view with. The Item Perspective component is responsible for managing the item rendered to the screen. The First Person Item Perspective component makes extensive use of the spring system to move the item in a realistic way while in a first person perspective.
When an ability is activated that performs an action on the item (such as a melee slash or grenade throw) it calls the corresponding Item Action component to perform the actual action. Multiple Item Action components can be added to the same item GameObject which will allow for the item to perform multiple functions. A classic example of this is an assault rifle that can shoot or be used as a blunt object and melee attack. Another example could be a light sword attack or a heavy sword attack.
The Item Perspective Properties is the last type of component that you’ll see added to an Item GameObject and this component is responsible for storing values specific to the corresponding perspective for the Item Action component. As an example the Shootable Weapon component will use the First Person Perspective Properties component to point to the location of the muzzle flash for the first person assault rifle. A Third Person Perspective Properties component will point to the location of the muzzle flash for the third person assault rifle.
With all of these components added to the Item GameObject you’ll see a setup similar to the image below. In this image the item is setup for both a first and third person perspective, and it also can be used as a shootable weapon or a melee weapon.
Inspected Fields
Item Definition
A reference to the object used to identify the item.
Slot ID
Specifies the inventory slot/spawn location of the item.
Animator Item ID
Unique ID used for item identification within the animator.
Animator Movement Set ID
The movement set ID used for within the animator.
Dominant Item
Does the item control the movement and the UI shown?
Unique Item Set
Does the item belong to a unique Item Set?
Allow Camera Zoom
Can the camera zoom when the item is equipped?
Drop Prefab
The GameObject that is dropped when the item is removed from the character.
Full Inventory Drop
When the item is dropped should the entire item be dropped? Throwable Items will want this option enabled.
Drop Consumable Items
Should the consumable items be dropped along with the current item?
Equip Event
Specifies if the item should wait for the OnAnimatorItemEquip animation event or wait for the specified duration before equipping. This field uses an Animation Event Trigger.
Equip Complete Event
Specifies if the item should wait for the OnAnimatorItemEquipComplete animation event or wait for the specified duration before stopping the equip ability. This field uses an Animation Event Trigger.
Equip Animator Audio State Set
Specifies the animator and audio state from an equip. This field uses an Animator Audio State Set.
Unequip Event
Specifies if the item should wait for the OnAnimatorItemUnequip animation event or wait for the specified duration before unequipping. This field uses an Animation Event Trigger.
Unequip Complete Event
Specifies if the item should wait for the OnAnimatorItemUnequipComplete animation event or wait for the specified duration before stopping the unequip ability. This field uses an Animation Event Trigger.
Unequip Animator Audio State Set
Specifies the animator and audio state from an unequip. This field uses an Animator Audio State Set.
UI Monitor ID
The ID of the UI Monitor that the item should use.
Icon
The sprite representing the icon.
Show Crosshairs On Aim
Should the crosshairs be shown when the item aims?
Center Crosshairs
The sprite used for the center crosshairs image.
Quadrant Offset
The offset of the quadrant crosshairs sprites.
Max Quadrant Spread
The max spread of the quadrant crosshairs sprites caused by a recoil or reload.
Quadrant Spread Damping
The amount of damping to apply to the spread offset.
Left Crosshairs
The sprite used for the left crosshairs image.
Top Crosshairs
The sprite used for the top crosshairs image.
Right Crosshairs
The sprite used for the right crosshairs image.
Bottom Crosshairs
The sprite used for the bottom crosshairs image.
Show Full Screen UI
Should the item’s full screen UI be shown?
Events
Four Unity events are exposed by the item:
- Pickup Item
- Equip Item
- Unequip Item
- Drop Item
These events can be assigned within the item’s inspector.