Simple Inventory
Lightweight list-based inventory for prototypes. Add, remove, and check items without UI complexity.
No APIs that Unity 6.0 to 6.6 made obsolete or removed. How this is checked
What it adds to your GameObject
A MonoBehaviour component: attach it to a GameObject. This is the Inspector you get, read from the source: 8 serialized fields with their defaults.
When to use it
Perfect for game jam prototypes, RPGs, survival games, and any project that needs basic item tracking without a full UI system. Ideal when you need quick add/remove/check operations. Pair with Pickup Collectible for world pickups and JSON Save Utility for persistence.
Setup
- Attach SimpleInventory to your player
- Add items: inventory.AddItem("sword", 1)
- Remove items: inventory.RemoveItem("coin", 5)
- Check items: inventory.HasItem("key")
- Get count: inventory.GetItemCount("arrow")
- Hook OnInventoryChanged to refresh your UI
- For full drag-and-drop UI, use the Complete Inventory System instead
Features
- Add, remove, and check items with simple method calls
- Configurable max slots and max stack size per item
- UnityEvents for item added, removed, and inventory changed
- Read-only Items list for safe UI binding
- Automatic stacking of identical items up to max stack size
- IsFull property and slot count tracking
Inspector fields
Every field Simple Inventory exposes in the Inspector, with the default it starts at.
| Field | Type | Default | Group |
|---|---|---|---|
Item IditemId | string | empty | |
Quantityquantity | int | 0 | |
Max SlotsmaxSlots | int | 20 | Settings |
Max Stack SizemaxStackSize | int | 99 | Settings |
On Inventory ChangedOnInventoryChanged | UnityEvent | No listeners | Events |
On Item AddedOnItemAdded | UnityEvent<string, int> | No listeners | Events |
On Item RemovedOnItemRemoved | UnityEvent<string, int> | No listeners | Events |
Itemsitems | List<ItemEntry> | Empty | Events |
Public API
What other scripts can call on SimpleInventory.
| Member | Returns | Description |
|---|---|---|
AddItem(string itemId, int quantity = 1) | int | Add items to inventory. Returns the amount actually added. |
RemoveItem(string itemId, int quantity = 1) | int | Remove items from inventory. Returns the amount actually removed. |
HasItem(string itemId, int quantity = 1) | bool | Check if inventory contains at least 'quantity' of an item. |
GetItemCount(string itemId) | int | Get the quantity of an item in inventory. |
Clear() | void | Clear all items from inventory. |
Items property | IReadOnlyList<ItemEntry> | Read-only access to inventory items. |
SlotCount property | int | Number of unique item stacks. |
IsFull property | bool | Check if inventory is full (all slots used). |
Common mistakes
Don't forget to set maxSlots and maxStackSize in the Inspector — the defaults (20 slots, 99 stack) may not fit your game. AddItem returns 0 if the inventory is full, so always check the return value. If OnInventoryChanged isn't firing, make sure you're calling AddItem/RemoveItem through the script rather than modifying the list directly.
Source code
SimpleInventory.cs, 115 lines, MIT licensed. Paste it into a new C# file of the same name.
using UnityEngine;
using UnityEngine.Events;
using System.Collections.Generic;
/// <summary>
/// Lightweight inventory system using a simple list.
/// Perfect for prototypes and jam games.
/// </summary>
public class SimpleInventory : MonoBehaviour
{
[System.Serializable]
public class ItemEntry
{
public string itemId;
public int quantity;
public ItemEntry(string id, int qty)
{
itemId = id;
quantity = qty;
}
}
[Header("Settings")]
[SerializeField] private int maxSlots = 20;
[SerializeField] private int maxStackSize = 99;
[Header("Events")]
public UnityEvent OnInventoryChanged;
public UnityEvent<string, int> OnItemAdded;
public UnityEvent<string, int> OnItemRemoved;
[SerializeField] private List<ItemEntry> items = new List<ItemEntry>();
/// <summary>Read-only access to inventory items.</summary>
public IReadOnlyList<ItemEntry> Items => items;
/// <summary>Number of unique item stacks.</summary>
public int SlotCount => items.Count;
/// <summary>
/// Add items to inventory. Returns the amount actually added.
/// </summary>
public int AddItem(string itemId, int quantity = 1)
{
int added = 0;
// Try to stack with existing
ItemEntry existing = items.Find(i => i.itemId == itemId);
if (existing != null)
{
int canAdd = Mathf.Min(quantity, maxStackSize - existing.quantity);
existing.quantity += canAdd;
added = canAdd;
}
else if (items.Count < maxSlots)
{
int toAdd = Mathf.Min(quantity, maxStackSize);
items.Add(new ItemEntry(itemId, toAdd));
added = toAdd;
}
if (added > 0)
{
OnItemAdded?.Invoke(itemId, added);
OnInventoryChanged?.Invoke();
}
return added;
}
/// <summary>
/// Remove items from inventory. Returns the amount actually removed.
/// </summary>
public int RemoveItem(string itemId, int quantity = 1)
{
ItemEntry existing = items.Find(i => i.itemId == itemId);
if (existing == null) return 0;
int removed = Mathf.Min(quantity, existing.quantity);
existing.quantity -= removed;
if (existing.quantity <= 0)
items.Remove(existing);
OnItemRemoved?.Invoke(itemId, removed);
OnInventoryChanged?.Invoke();
return removed;
}
/// <summary>Check if inventory contains at least 'quantity' of an item.</summary>
public bool HasItem(string itemId, int quantity = 1)
{
ItemEntry entry = items.Find(i => i.itemId == itemId);
return entry != null && entry.quantity >= quantity;
}
/// <summary>Get the quantity of an item in inventory.</summary>
public int GetItemCount(string itemId)
{
ItemEntry entry = items.Find(i => i.itemId == itemId);
return entry?.quantity ?? 0;
}
/// <summary>Clear all items from inventory.</summary>
public void Clear()
{
items.Clear();
OnInventoryChanged?.Invoke();
}
/// <summary>Check if inventory is full (all slots used).</summary>
public bool IsFull => items.Count >= maxSlots;
}