Godot autoload architecture

From thedivergentai/GD-Agentic-Skills · View interactive version

Godot autoload architecture is an AI agent skill from the GitHub repository thedivergentai/GD-Agentic-Skills. Expert patterns for Godot AutoLoad (singleton) architecture including global state management, scene transitions, signal-based communication, dependency injection, autoload initialization order, and anti-patterns to avoid. Use for game managers, save systems, audio controllers, or cross-scene resour

How to use this skill

Skill file

Available Scripts

[autoload_init_order_diag.gd](scripts/autoload_init_order_diag.gd)

MANDATORY before trusting a multi-Autoload dependency graph — verifies boot sequence.

[singleton_dependency_diagram.gd](scripts/singleton_dependency_diagram.gd)

MANDATORY with the mermaid/order diagram — maps who may call whom at boot.

[global_event_bus.gd](scripts/global_event_bus.gd)

MANDATORY before a cross-system Autoload bus (Achievements, UI, Save events).

[safe_scene_switcher.gd](scripts/safe_scene_switcher.gd)

MANDATORY before Autoload-owned scene transitions (deferred free / root management).

[service_locator.gd](scripts/service_locator.gd) / [service_registry.gd](scripts/service_registry.gd)

MANDATORY before Engine.register_singleton DI for non-Node services.

[persistent_data_holder.gd](scripts/persistent_data_holder.gd)

Data that must survive change_scene_to_file() (inventory, settings).

[static_state_manager.gd](scripts/static_state_manager.gd)

static var global state when you do not need a SceneTree Node.

[lazy_loaded_singleton.gd](scripts/lazy_loaded_singleton.gd)

On-demand instantiate instead of eager boot cost.

[cross_autoload_comms.gd](scripts/cross_autoload_comms.gd)

Safe cross-singleton calls after both are ready.

[thread_safe_global_access.gd](scripts/thread_safe_global_access.gd)

Mutex / call_deferred for background threads touching Autoload state.

[autoload_reference_checker.gd](scripts/autoload_reference_checker.gd) / [singleton_health_check_test.gd](scripts/singleton_health_check_test.gd)

Validate registration + defaults (debug / CI).

[autoload_bootstrapper.gd](scripts/autoload_bootstrapper.gd) / [autoload_initializer.gd](scripts/autoload_initializer.gd)

Ordered init helpers when _ready is too early for heavy work.

[debug_console_autoload.gd](scripts/debug_console_autoload.gd)

PROCESS_MODE_ALWAYS CanvasLayer console.

[global_game_state.gd](scripts/global_game_state.gd) / [stateless_bus.gd](scripts/stateless_bus.gd)

State holder vs pure event bus split.

NEVER Do in AutoLoad Architecture


When to Use AutoLoads

Good: Game/Audio/Save managers, SceneTransitioner, global score/inventory, cross-scene EventBus.

Avoid: Scene-specific logic, temporary state, pure data (prefer static / Resource), over-architecting tiny projects.


Expert Architecture Patterns

1. Boot order & dependency diagram

MANDATORY: Read autoload_init_order_diag.gd and singleton_dependency_diagram.gd before drawing or trusting any Autoload order.

Autoloads initialize top → bottom in Project Settings. Upper singletons must not call lower ones in _ready(). Move dependents down the list.

graph TD
    subgraph Autoloads [Project Settings order]
        B[1. GlobalAudio] --> C[2. ServiceLocator]
        C --> D[3. QuestManager]
    end
    D --> E[Current Scene]
    E -->|Queries| C

2. Service locator (non-Node DI)

MANDATORY: service_locator.gd / service_registry.gd before Engine.register_singleton.

Use for lightweight RefCounted services; unregister in _exit_tree to avoid dangling engine singletons.

3. Event bus vs state holder

MANDATORY: global_event_bus.gd for cross-system past-tense events. Keep mutable run state in persistent_data_holder.gd / global_game_state.gd — not on the bus.

4. Safe scene switching from Autoload

MANDATORY: safe_scene_switcher.gd — deferred free + root ownership. Pair with godot-scene-management for threaded loads.

5. Health checks

MANDATORY in debug/CI: singleton_health_check_test.gd / autoload_reference_checker.gd — assert presence + Engine.has_singleton for registered services.

Expert insights (WHY — keep in body)

Deep recipes (on demand)

| Topic | Reference / script |

|-------|-------------------|

| Service locator / boot diagram / health checks | expert-patterns.md |

| Beginner registration only | autoload-patterns.md |

Reference

Progressive disclosure: open Official Documentation links only when researching a specific API; load Related Skills when routing to a peer domain — do not preload the whole lattice.

Official Documentation

Related Skills

Prerequisites
Complements
Downstream / consumers
Master
Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.