Guide
Items
Give the player items that can be equipped, held in the right hand, put away and used. In this guide you create an item container, add items to it, and control switching with the keyboard and mouse wheel.
On this page
How the parts fit together#
ItemContaineron a child of the right hand- The list of items. Its order defines the slots: the first item is slot 1. Items stay inactive until they are equipped.
HandItemSocketon the player root- Holds the equipped item in the hand and owns the equip and unequip events.
ItemSwitcheron the player root- Reads the number keys, Q and the mouse wheel, and calls the container.
ItemHoldDataon each item- The item's id, its grip and IK settings, its world prefab and its item-local events.
ItemDefinitionoptional asset- A shared description of an item: id, name, categories and prefabs. Covered in Definitions and categories.
Add items#
Use the Item Container Setup window, or set up each item by hand.
- Open .
- Set Target Container, or click Scan Scene for Container. The container must be in the scene.
- Drag an item prefab into Item Prefab and click 🚀 ADD ITEM. The window creates the item as an inactive child of the container. If the prefab has no
ItemHoldData, one is added. - Optional: open Advanced IK Offsets to set the hold layer, grip offsets, hand and elbow offsets, hold style, pitch influence and vertical limits. Load IK Preset with Apply Preset fills the same fields from an
ItemIKPreset. - The Inventory list shows the items in slot order. Extract copies the IK settings of an existing item into the form. X removes an item from the container.
To set up an item by hand, add an ItemHoldData with a unique itemId to the item prefab, then add the item to the container's Items list.
Item hold data#
ItemHoldData is the item's configuration. Its itemId defaults to NewItem, so change it for every item. EquipItemById and world item pickups use this id.
itemIdstring default NewItem- Unique id. A pickup matches a
WorldItemto the item by this id. definitionItemDefinition- Optional. When set, the id, categories and world prefab come from the definition.
categoryItemCategory default None- Category flags, used when no definition is set.
worldItemPrefabGameObject- The prefab spawned when the item is dropped. It needs a
WorldItemcomponent. attachmentDataItemAttachmentData- Grip, hold style and IK settings. See Grips and IK.
OnEquip,OnUnequip,OnUseUnityEvent- The item's own reactions, for example switching a light on.
OnEquipandOnUnequiponly fire for items that are shown.
Equip, switch, holster and use#
| Input | Effect |
|---|---|
| 1 to 9 | Equips the item in slot 1 to 9. Pressing the number of the item that is already equipped puts it away. |
| 0 or Q | Puts the current item away. |
| Mouse wheel | Scroll up for the previous item, down for the next. Cycling wraps around. |
| F | Uses the held item. This fires its OnUse event (the demo uses F for the flashlight). |
Switching plays a holster animation. The current item is lowered out of view, and then the new one is raised. The timings are on PlayerHandIK under Holster:
holsterDurationfloat default 0.2- Seconds to lower the hand out of view.
drawDurationfloat default 0.25- Seconds to raise the hand into view.
drawStartWeightfloat default 0.6- The hand IK weight that must be reached before the draw starts, so the arm does not swing up from the idle pose.
holsterOffset,holsterTiltAngledefault tilt 50- Where the hand goes when lowered, and how far the item tips.
To turn the animation off, disable Smooth Transitions on HandItemSocket (on by default). Stow Timeout (default 1 second) completes a put-away even if the hand never reaches the lowered pose.
Pick up and drop#
The demo scripts add pickup and drop. The core package does not include them.
- E picks up the item you look at (
PlayerInteraction). Only colliders on the layers in its Interactable Layer count. - G drops the held item (
PlayerDropSystem). The item's World Item Prefab is spawned in front of the camera and the item leaves the hand at once.
Definitions and categories#
An ItemDefinition describes an item in one place. Create one with .
- Id: until you press Lock, the id follows the asset name. Lock it before you use the id in save data.
- Display Name: shown in pickup prompts. It falls back to the asset name.
- Category: flags
Tool,ElectricandConsumable. An item can have several. Check them withIs(ItemCategory). - Held Prefab, World Prefab and Network Prefab: the hand item, the dropped item and the networked variant of the dropped item (used by the add-ons).
Assign the definition to ItemHoldData, to WorldItem or to the starter items of the demo PlayerInventory. Item id fields then show a picker with all definitions, and items without a definition keep working with a plain id.
Grips and IK#
Each item has its own grip and IK settings in ItemAttachmentData. The most common fields:
holdStyleHoldStyle default OneHandedRightOneHandedRightorTwoHanded. Two-handed items use the left-hand offsets.gripPositionOffset,gripRotationOffsetVector3- Where the item sits in the palm, relative to the hand socket.
overrideHandOffset,handOffsetdefault 0.25, −0.15, 0.4- Turns on a custom hand position while standing. The value is relative to the camera.
overrideElbowOffset,elbowHintOffset- Custom elbow position while standing. Crouch variants exist for the hand and elbow.
pitchInfluence,pitchRotationInfluencedefault 0.3 and 0.5- How much looking up or down moves and tilts the hand.
fingerPoseRight,fingerPoseLeft- Finger grip templates. See Finger grips.
Tune an item in the scene#
- On the item's
ItemHoldData, enable Debug Mode and Tune Grip Mode. - Enter Play Mode and equip the item.
- Move the item in the Scene view. Its transform is captured into the grip offsets.
For the hand and elbow targets, enable Tune Handles Mode instead. Handles then move the targets for the current stance (standing or crouching). Handles work only in Play Mode with the item equipped, Debug Mode on and the player standing still. A label shows why the handles are locked.
IK presets#
An ItemIKPreset stores a complete set of ItemAttachmentData so several items can share it. Create one with . In the item's Inspector, the Preset Management section works with it:
- Load Preset: copies the preset into the item.
- Update Preset: copies the item's current settings into the preset.
- Create New Preset Asset: saves the item's settings as a new preset.
Item events#
| Source | C# event | UnityEvent |
|---|---|---|
HandItemSocket | ItemEquipped, ItemUnequipped | OnItemEquipped, OnItemUnequipped |
ItemContainer | none | OnContainerChanged, fired when items are added or removed |
ItemHoldData | none | OnEquip, OnUnequip, OnUse |
With smooth transitions, ItemUnequipped fires while the old item is still visible. ItemEquipped can fire for an item that is still waiting to be drawn. Code and listeners are covered in Event API.