User Tools

Site Tools


The inventory system consists of the Inventory GUI, the Player Inventory, and the Inventory Database.

Inventory GUI

Before the Inventory GUI can be used it must be connected to a PlayerInventory. You can make this connection with UI.Inventory.connect_to_inventory(new_inventory: PlayerInventory).

The Inventory GUI is hidden by default. To show it use

The Inventory GUI consists of 2 parts: the Hotbar and the Mainbox. Currently these cannot be hidden separately. See Issue #23.

Both the Hotbar and the Mainbox contain a number of Item UI elements.


The hotbar is connected to the first 10 slots of the players inventory.


The mainbox is connected to slots 11-40 of the player's inventory.

Item UI

These visually represent a single item in the players inventory.

Player Inventory

The Player Inventory is contained in a PlayerInventory object. You can access the current player inventory at Player.inventory.

Adding an item to inventory:

# From within
# Here we have an item named sapling
if (inventory.add_item(sapling)):
  print("Item was added successfully.")
  print("Item failed to add, probably out of space")

Adding an item to a specific inventory slot:

# From within
# Overwrites item in slot 40
inventory.add_item(sapling, 39)

Swapping two item slots:

# From within
# Swap first hotbar item with first mainbox item

Remove an item from the inventory:

# From within

Get a reference to an inventory item:

# From within
# Will return InventoryItem or null

Inventory Database

The Inventory Database subsystem manages the loading and defining of various types of items.

It starts by loading all of the .tres files from resources/inventory_db/items/. The resulting InventoryDBItem objects are available as a dictionary at DB.Inventory.item_list. The keys of this dictionary are named after the filename.

These InventoryDBItem objects are then used as essentially a class definition for InventoryItem objects.


New item types can be created from the Godot GUI by right-clicking the items folder and selecting New Resource and then selecting InventoryDBItem from the menu.

You can also create new items by manually creating the .tres file:

[gd_resource type="Resource" load_steps=3 format=2]

[ext_resource path="res://scenes/databases/inventory_db/" type="Script" id=1]
[ext_resource path="res://assets/inventory/ITEM_ICON_FILENAME.png" type="Texture" id=2]

script = ExtResource( 1 )
item_name = "item_name_should_match_filename"
display_name = "Pretty display name"
icon = ExtResource( 2 )
max_stack = 100

Either way the item_name property should match the name of the .tres file.


InventoryItem objects represent actual items that could be placed into a player inventory slot.

To instantiate an item:

# Where apple_sapling is the name of any InventoryDBItem
var sapling: InventoryItem ="apple_sapling")

To adjust the amount:

sapling.amount = 2

To access the underlying InventoryDBItem:

# Please treat access to the db property as Read-Only
# Print the display name

Class Reference


docs/inventory.txt · Last modified: 2021/02/04 02:59 by