Skip to content

Lesson 6 of 9 · 25m

Resources, Autoloads, and Groups Without Hidden Coupling

Use custom resources for data, autoloads for rare process-wide services, and groups for dynamic membership while avoiding invisible dependencies.

Every Godot project eventually invents the same three monsters: a singleton that knows everything, a static script that secretly loads everything, and a group name only one person remembers. Resources, autoloads, and groups are good tools. They become dangerous when they let code bypass ownership and dependency direction.

Resources are typed data objects

A custom resource models game data as inspectable content:

class_name WeaponData
extends Resource

@export var display_name: String
@export var damage: int = 1
@export var cooldown: float = 0.5
@export var projectile_scene: PackedScene

Save instances as .tres files and designers can tune them in the inspector. Typed resources validate fields, reference scenes and audio, and diff well as text. The resource describes the item; it should not secretly know the player who might equip it.

Autoloads are process-wide services

Autoloads are appropriate for things that remain meaningful across scenes: save coordination, audio routing, scene transitions, or platform services.

# SaveSystem.gd, registered as autoload SaveSystem
extends Node
signal save_completed

func save_game(data: Dictionary) -> void:
    var file := FileAccess.open("user://savegame.save", FileAccess.WRITE)
    file.store_string(JSON.stringify(data))
    file.close()
    save_completed.emit()

The test is simple: would this object make sense if a different scene were active? If not, it is not an autoload. Player health, level state, and inventory usually belong in scenes.

Groups are membership, not architecture

Groups solve transient classification problems:

func _ready() -> void:
    add_to_group("damageable")

func explode() -> void:
    for node in get_tree().get_nodes_in_group("damageable"):
        if node is Damageable:
            node.damage(blast_damage)

They are useful when membership is dynamic and heterogeneous. They are weak as a substitute for types because group names are strings and membership does not guarantee an interface.

Keep dependencies visible and storage correct

Autoloads initialize before the active scene, which makes them convenient enough to abuse. Prefer passing services where practical:

func configure(save_system: SaveSystem) -> void:
    self.save_system = save_system

Also separate project data from user data. res:// is packaged content and often read-only after export. user:// is per-user writable storage for saves, settings snapshots, and generated cache files.

Field notes

  • Rename class_name carefully; serialized scripts and resources can retain old references.
  • Loaded resources are shared by default, so duplicate them when instance-specific mutation is intended.
  • Autoload order matters when one singleton uses another during initialization.
  • user:// varies by platform; never hard-code machine paths.
  • Type-check group members before trusting that they implement the method you intend to call.

Was this lesson helpful?

Sign in to rate