Video summary

Data models - using data to create extensible, maintainable games in Godot

Main summary

Key takeaways

Technology

Main idea: replace node-heavy item logic with data models (Godot Resources)

  • The tutorial explains that building all item/game logic directly with Godot Nodes/Scenes becomes hard to extend and maintain as features grow (e.g., the same weapon must exist both in-world and in inventory/in-dialogs).
  • It introduces data models as “plain objects” that store item data independent of how it’s rendered/used.
  • Focus: using Godot Resource types to represent:
    • Items (name, 3D representation, UI icon, later price)
    • Inventory contents
    • Crafting Recipes (ingredients and results)
  • Goal: make systems reusable and extensible—UI, world pickup, inventory, and crafting all consume the same data.

Tutorial 1: World pickup using data models

Problem implemented

  • Player (“Mr. G”) moves around and collects items from the ground.

Key technical approach

  • Use an Area3D with collision shape and body_entered signal to detect pickup.
  • Define a contract: the player implements on_item_picked_up(...), and the pickup calls it when the player enters the area.
  • Initially, the tutorial demonstrates an items database as a Dictionary script:
    • items.gd stores entries keyed by an item ID
    • Each item entry initially contains name and later a scene path for world representation
  • The pickup node exposes an exported item_id and then:
    • looks up the item in the database
    • gives the player the ID so the player can resolve item data
    • instantiates the item’s 3D scene under the pickup automatically

Drawbacks called out

  • Typos are easy:
    • wrong item_id strings
    • wrong keys in the database dictionary
  • Using scene paths as strings can silently break when scenes move/rename.
  • Large dictionaries (hundreds of items) become difficult to maintain.

Tutorial 2 (better): Use Godot custom Resource for Items

Item resource

  • Create item.gd extending Godot Resource.
  • Use exported fields editable in the inspector:
    • name (String)
    • scene (PackedScene) for the 3D representation
    • later icon (Texture2D) and price (int)
  • Advantages emphasized:
    • PackedScene fixes references more robustly than hard-coded strings/paths.
    • Godot maintains references when reorganizing/renaming assets.
    • Avoids item-ID string typing errors.

How pickup changes

  • Pickup now exports a direct reference to an item: Item resource.
  • The pickup instantiates item.scene in ready().
  • Instead of calling on_item_picked_up(id), it calls on_item_picked_up(item).

Player/inventory simplification

  • Player no longer needs an items database lookup:
    • it directly uses fields from the received item resource (e.g., item.name).

Reusable component

  • The pickup is saved as a separate scene (e.g., pickup.tscn) so it can be duplicated and configured per item (pickaxe, sword, etc.).

Tutorial 3: Inventory as a data model + inventory dialogue UI

Inventory model

  • inventory.gd extends RefCounted.
  • Stores:
    • content: Array[item]
  • Methods:
    • add_item(item)
    • remove_item(item) (removes first occurrence)
    • get_items()

Inventory integration

  • Player owns an inventory instance.
  • Pickup calls player.inventory.add_item(item).

Inventory UI

  • Builds inventory_dialog.tscn (PanelContainer with title + close button).
  • Uses an item_slot.tscn scene to show an item icon.
  • inventory_dialog.gd:
    • open(inventory) populates a grid with one slot per inventory item
    • connects close button to hide the dialogue
    • uses scene-unique node names so script references don’t break when UI hierarchy changes
  • Input handling:
    • Added CanvasLayer and a UI root.gd script.
    • Pressing an input action (key I) opens the inventory dialogue.
    • Fix for 3D mouse capture: dialogue shows mouse (input.mouse_mode_visible) and restores captured mode when closing.
  • Bugfix covered:
    • Opening the dialogue multiple times initially duplicates slots; fixed by clearing grid children before repopulating.

Tutorial 4: Crafting system using Resource-based data models

Crafting data

  • recipe.gd extends Resource with exported fields:
    • name
    • ingredients: Array[item]
    • results: Array[item]
  • Multiple recipe resources are created in a recipes folder:
    • Example: iron ingot recipe, pickaxe recipe, etc.

Crafting dialogue

  • crafting_dialog.tscn is derived from inventory UI layout:
    • left side: recipe list (ItemList)
    • right side: ingredient grid + result grid
    • craft button
  • The tutorial adds a reusable UI component:
    • item_grid scene that can display arrays of items (using item_slot icons).
  • Wiring selection to recipe data:
    • When populating the ItemList, it uses metadata:
      • set_item_metadata(index, recipe)
    • On selection change, retrieves the recipe with get_item_metadata(...).

Crafting behavior

  • Craft button handler:
    • removes each ingredient item from the inventory
    • adds each result item to the inventory
  • Two key fixes implemented:
    1. Auto-select first recipe on open:
      • calls list select(0) and manually triggers the selection update because selection-by-code doesn’t emit the same signal.
    2. Disable craft unless inventory contains all ingredients:
      • adds inventory.has_all(items_array):
        • duplicates the required array
        • iterates inventory content and erases matches from the “needed” list
        • returns true if nothing remains

Recursive crafting dependency tested

  • Example flow tested:
    • Add iron ore → craft iron ingots → craft pickaxe
    • Craft button correctly disables/enables based on ingredient availability.

Export/runtime loading fix: dynamically load recipes reliably

Issue

  • In-editor loading works, but exported builds fail to load recipe .tres files.
  • Reason explained:
    • Godot export packs resources into .pck and may rename/replace .tres into .remap entries.
    • A filesystem-based approach (listing DirAccess) breaks at runtime because paths/filenames don’t match the expected .tres layout.

Initial workaround discussed

  • “Hacky” approach: detect .remap—rejected as fragile.

Robust solution via plugin

  • Uses a plugin: Godot Resource Groups
    • Creates a ResourceGroup resource (e.g., all_recipes.tres)
    • Configured to include recipes/*.tres
    • The plugin maintains an up-to-date list of resource paths (handles adds/removes/renames)
  • The crafting dialogue’s script exports this resource group and calls load_all_into(...).
  • Verified by exporting and testing: all recipes appear in exported game.

Data maintenance / balancing workflow: editing many item fields

Problem addressed

  • When adding fields like price, default values cover new fields, but custom tuning becomes tedious at scale (hundreds of items).
  • Also lack of spreadsheet-like overview makes balancing hard.

Solution via plugin

  • Uses plugin: Edit Resources as Table 2
    • Adds a “resource tables” tab in Godot
    • Automatically collects items/resources from a folder (e.g., data/items)
    • Provides table view with sorting/filtering
    • Supports bulk editing and filtering via GDScript expressions (example shown: res.price is less than seven)
  • Purpose: easier balancing by editing game data directly in-editor with spreadsheet-like tooling.

Key takeaways / “what you learn”

  • Represent items/recipes as Godot Resources rather than node graphs or string-based dictionaries.
  • Use exported PackedScene, Texture2D, and direct resource references to avoid typos and broken paths.
  • Build reusable UI components that consume the same data models:
    • inventory dialogue, crafting dialogue, item slots/grids
  • Use proper separation of concerns:
    • pickups interact with item resources
    • player stores inventory data model
    • UI displays data model without embedding gameplay logic
  • For scalable data loading in exported builds:
    • don’t rely on directory scanning for .tres
    • use a resource grouping plugin (Resource Groups)
  • For maintainability of large datasets:
    • use resource table editor plugin to balance/tweak values like prices.

Main speakers / sources

  • Source: Single tutorial video narrator (no distinct named speakers provided in subtitles).
  • Product/engine source referenced: Godot Engine (official features like Nodes/Scenes, Resources, signals, PackedScene, export workflow).

Original video