A slot-based inventory for Godot 4 with stacking, drag and drop, item tooltips, using items, and save data. The data and the UI are separate, so you can keep the logic and restyle the window.
Itemresources. One.tresfile per item, with a name, icon, description, stack limit, rarity, value, type and optional equipment stats.- Stacking. Items stack up to their
max_stack, then spill into the next free slot. Non-stackable gear takes one slot each. - Overflow reporting.
add_item()returns how many did not fit, so you can leave the rest on the ground or show "bag full". - Drag and drop with Godot's built-in GUI drag system: drop on an empty slot to move, on the same item to stack, on a different item to swap.
- Tooltips that open next to the mouse and stay on screen, with the item name in its rarity colour and equipment stats listed.
- Using items. Right click uses an item; consumables are used up and the UI
emits
item_usedso your game can react. - Save and load.
save_data()returns a plain dictionary that refers to items by resource path, andload_data()puts it back. - Data and UI are separate.
Inventoryis a plain node with signals.InventoryUIlistens and redraws, so any number of windows can show one bag.
demo/InventoryDemo.tscn starts with a small kit: potions, a sword and a shield.
Press I to open and close the bag, click items, drag them around, and press
1 to add random loot.
- Godot 4.7 or later, standard build (GDScript only, no .NET needed).
- Tested on Godot 4.7.2 stable on Windows. Earlier 4.x versions are untested.
- Uses the Compatibility renderer, so it runs on older GPUs too.
Clone the repository:
git clone https://github.com/CodingQuests/godot-inventory-system.gitOr download it with Code > Download ZIP and unzip it.
Then open Godot, click Import, pick the project.godot file inside the folder,
and click Import & Edit.
- Press F5.
- Left click an item to see its details.
- Right click a potion to use it.
- Drag an item onto another slot. Drop potions on potions to stack them.
- Press 1 a few times to add loot, 2 to empty the bag, S to save the contents and L to load them back. I opens and closes the bag.
Item(aResource) is what an item is. The same resource is shared by every slot that holds it, so two slots hold the same item whenslot_a.item == slot_b.item.InventorySlot(aResource) is one cell: an item and a quantity. It emitsitem_changedwhenever either changes.Inventory(aNode) owns the slots and the rules: add, remove, count, stack, save.
Adding stacks onto matching slots first, then fills empty ones, and hands back whatever is left:
var overflow := inventory.add_item(health_potion, 30)
if overflow > 0:
drop_on_ground(health_potion, overflow)InventoryUI builds one InventoryUISlot per inventory slot and listens for
inventory_changed. It never decides anything itself: a drop calls the slots'
merge_with() or swaps their contents, and the display updates from the signals.
Each InventoryUISlot uses Godot's own drag and drop callbacks:
| Callback | What it does here |
|---|---|
_get_drag_data() |
Returns {slot_index, item, quantity} and a preview of the icon |
_can_drop_data() |
Accepts any slot data and highlights the slot green |
_drop_data() |
Emits slot_dropped(from, to); InventoryUI stacks or swaps |
var data := inventory.save_data() # {"size": 20, "slots": [{"item_path": "res://items/iron_sword.tres", "quantity": 1}, null, ...]}
inventory.load_data(data)Items are stored by resource path, so the save stays small and picks up any changes you make to an item's stats later.
project.godot Project file and the toggle_inventory action
inventory/Item.gd An item definition (Resource)
inventory/InventorySlot.gd One slot: item and quantity (Resource)
inventory/Inventory.gd The bag: slots, stacking, add, remove, save
inventory/GUI/InventoryUI.tscn The inventory window: grid plus info panel
inventory/GUI/InventoryUI.gd Builds the grid, handles clicks, drops and tooltips
inventory/GUI/InventoryUISlot.tscn One cell: icon and quantity
inventory/GUI/InventoryUISlot.gd Drawing a slot and drag and drop
items/ Six example items (.tres)
demo/InventoryDemo.tscn The demo scene
demo/inventory_demo.gd Demo only: starting kit, loot keys, messages
assets/kenney_tiny-dungeon/ Kenney Tiny Dungeon item icons (CC0) and their license
-
Copy the
inventory/folder into your project. -
Add an input action named
toggle_inventory(Project > Project Settings > Input Map) and bind a key to it. -
Add an
Inventorynode to your player. -
Instance
inventory/GUI/InventoryUI.tscnunder aCanvasLayerand set itsinventoryproperty to that node. -
Make your items: right click in the FileSystem dock, New Resource, pick
Item, fill it in, and save it as a.tres. -
Add items from gameplay:
@export var potion: Item func _on_pickup(body: Node) -> void: var left: int = body.get_node("Inventory").add_item(potion, 1) if left == 0: queue_free()
-
React to use: connect
InventoryUI.item_used, or extendItemand overrideuse().
- Size:
inventory_sizeon theInventorynode (20 by default). - Layout:
columns,slot_sizeandslot_spacingonInventoryUI. - Look: the
StyleBoxFlatresources inInventoryUI.tscn, andcreate_slot_style()inInventoryUISlot.gd. - Rarity colours:
get_rarity_color()inItem.gd. - Item behaviour: make a script that
extends Item, overrideuse(), and use it for those items' resources.
- Equipment stats are shown in the tooltip but nothing equips them. Hook
item_usedup to your own equipment or stats system. - Splitting a stack (taking half) is not built in.
use()only removes one of an item when its type is Consumable. Other types are left in the bag for your game to handle.- Saves store items by resource path. Moving or renaming an item's
.tresfile breaks old saves unless you migrate them. - The demo is a UI on a plain background, not a game scene.
- Tested on Godot 4.7.2 on Windows only.
MIT for the code. See LICENSE.
The item icons are from Tiny Dungeon by
Kenney, released under CC0 1.0. Details in
THIRD_PARTY_ASSETS.md, and the pack's original license is
in assets/kenney_tiny-dungeon/License.txt.
Want to understand how this works instead of just copying it?
CodingQuests teaches you how to build systems like this step by step in Godot, with interactive lessons and real projects.
- Inventory System builds this inventory from the data model up: items, slots, the UI and using items. Free, 10 lessons.
- Advanced Inventory UI carries on with an equipment paper doll, a hotbar, sorting and tooltips that compare gear. It is part of the paid Guild Hall membership.
Other free, MIT-licensed Godot 4 projects that work well next to this one:
- Save System: Save slots where picked-up items stay picked up and opened chests stay open.
- Stats and Leveling: Health and mana pools, attributes, modifiers tagged by source, an XP curve and stat points.
- Dialogue and Quest System: Branching dialogue with conditions and effects, quests that track themselves, and a visual dialogue editor.
- Menu System: Main, pause and options menus with saved settings, fade transitions and gamepad support.
All twelve are listed on the CodingQuests GitHub profile.
Made by CodingQuests.

