Unity Project Guide: Build Pickups, Inventory Slots, and a Hotbar
Inventory systems become confusing when beginners try to build everything at once: drag-and-drop, equipment, crafting, shops, storage chests, item rarity, icons, tooltips, and saving.
This guide builds a smaller but useful version:
Items are defined with ScriptableObjects.
The player can pick up items.
Inventory slots can stack items.
Number keys select a hotbar slot.
The selected slot can be consumed.
This gives you a foundation you can extend without rewriting everything.
Step 1: Create the Item Definition
Create a folder:
TEXT
1Assets/Items
Create ItemDefinition.cs.
CSHARP
1using UnityEngine;23[CreateAssetMenu(menuName ="Game/Item Definition")]4public class ItemDefinition : ScriptableObject5{6 public string itemId;7 public string displayName;8 public Sprite icon;9 public int maxStack =1;
In Unity:
Right-click in Assets/Items.
Choose Create > Game > Item Definition.
Name it Apple.
Set:
Item Id: apple
Display Name: Apple
Max Stack: 10
Consumable: enabled
Why ScriptableObjects? They let designers create item data in the editor without hardcoding every item in a script.
Step 2: Create an Inventory Slot Model
Create InventorySlot.cs.
CSHARP
1[System.Serializable]2public class InventorySlot3{4 public ItemDefinition item;5 public int quantity;67 public bool IsEmpty = item || quantity
This is not a MonoBehaviour. It is plain data.
Step 3: Create the Inventory Component
Create PlayerInventorySlots.cs.
CSHARP
Attach this script to the Player.
Step 4: Create Pickup Objects
Create a sprite in the scene called ApplePickup.
Add:
CircleCollider2D
Enable Is Trigger
Create ItemPickup.cs.
CSHARP
1using UnityEngine;23public class ItemPickup : MonoBehaviour4{5[SerializeField] private ItemDefinition item;6 SerializeField private int quantity
Attach it to ApplePickup and assign the Apple item definition.
Now the player can pick up apples.
Step 5: Add Hotbar Input
Create HotbarInput.cs.
CSHARP
1using UnityEngine;23public class HotbarInput : MonoBehaviour4{5 private PlayerInventorySlots inventory;67
Attach it to the Player.
Now number keys select slots, and E uses the selected consumable.
Step 6: Build a Simple Hotbar UI
Create a Canvas and add a horizontal layout:
Right-click Canvas.
Create UI > Panel.
Rename it Hotbar.
Add Horizontal Layout Group.
Create 8 child panels or buttons for slots.
For each slot, add:
An Image for the icon.
A TextMeshPro label for quantity.
A border or background image for selection.
Create HotbarSlotUI.cs.
CSHARP
1using TMPro;2using UnityEngine;3using UnityEngine.UI;45public class HotbarSlotUI : MonoBehaviour6
Create HotbarUI.cs.
CSHARP
1using UnityEngine;23public class HotbarUI : MonoBehaviour4{5[SerializeField] private PlayerInventorySlots inventory;6
Important: the unsubscribe shown above with _ => Render() creates a new delegate, so in production you should use named methods. For a cleaner version:
Then subscribe and unsubscribe with OnSelectionChanged.
Step 7: Test the System
Use this checklist:
Picking up one apple creates a stack.
Picking up several apples increases quantity.
Quantity stops at max stack and moves to another slot.
If all slots are full, pickup remains in the world.
Pressing number keys changes selection.
Pressing E consumes the selected apple.
Empty slots render as empty UI.
Step 8: Common Beginner Mistakes
Do not compare items by display name. Use the ScriptableObject reference or a stable item id.
Do not put all inventory code inside UI buttons.
Do not destroy pickups unless the item was actually added.
Do not save Sprite references directly in save files. Save item ids instead.
Where To Go Next
Next upgrades:
Add non-consumable items like keys.
Add equipment slots.
Save inventory to JSON.
Add drag-and-drop later, after the data model works.
Add item tooltips.
The main lesson is separation: item definitions describe what an item is, inventory slots describe what the player owns, and UI only renders the current state.