$npx -y skills add thedivergentai/GD-Agentic-Skills --skill godot-autoload-architectureExpert 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, o
| 1 | ## Godot 4.7 Baseline |
| 2 | |
| 3 | - Expert patterns in this skill target **Godot 4.7+** (stable, 2026-06-18). |
| 4 | - Consult the [Godot 4.7 migration guide](https://docs.godotengine.org/en/4.7/tutorials/migrating/upgrading_to_godot_4.7.html) when upgrading projects from 4.6. |
| 5 | - **NEVER** assume 4.6 defaults (stretch mode, audio area_mask, RichTextLabel percent flags) without checking 4.7 migration notes. |
| 6 | |
| 7 | # AutoLoad Architecture |
| 8 | |
| 9 | AutoLoads are Godot's singleton pattern, allowing scripts to be globally accessible throughout the project lifecycle. This skill guides implementing robust, maintainable singleton architectures. |
| 10 | |
| 11 | ## Available Scripts |
| 12 | |
| 13 | ### [static_state_manager.gd](scripts/static_state_manager.gd) |
| 14 | Using `static var` for high-performance global state that doesn't need SceneTree presence. |
| 15 | |
| 16 | ### [safe_scene_switcher.gd](scripts/safe_scene_switcher.gd) |
| 17 | Robust scene transitioning logic that handles deferred freeing and root-level management. |
| 18 | |
| 19 | ### [autoload_init_order_diag.gd](scripts/autoload_init_order_diag.gd) |
| 20 | Diagnostic utility for verifying and debugging the initialization sequence of Singletons. |
| 21 | |
| 22 | ### [global_event_bus.gd](scripts/global_event_bus.gd) |
| 23 | Centralized signal router for decoupling disparate systems (Achievements, Stats, Game Events). |
| 24 | |
| 25 | ### [persistent_data_holder.gd](scripts/persistent_data_holder.gd) |
| 26 | Pattern for data that must survive `change_scene_to_file()` (Inventory, Settings). |
| 27 | |
| 28 | ### [lazy_loaded_singleton.gd](scripts/lazy_loaded_singleton.gd) |
| 29 | Memory-efficient singleton pattern that instantiates on-demand rather than at boot. |
| 30 | |
| 31 | ### [debug_console_autoload.gd](scripts/debug_console_autoload.gd) |
| 32 | CanvasLayer-based debug overlay accessible from any game context. |
| 33 | |
| 34 | ### [cross_autoload_comms.gd](scripts/cross_autoload_comms.gd) |
| 35 | Expert rules and safety checks for communication between multiple Singletons. |
| 36 | |
| 37 | ### [thread_safe_global_access.gd](scripts/thread_safe_global_access.gd) |
| 38 | Using Mutex and `call_deferred` to safely access global data from background threads. |
| 39 | |
| 40 | ### [autoload_reference_checker.gd](scripts/autoload_reference_checker.gd) |
| 41 | Validation utility to ensure Autoloads are correctly registered before attempting access. |
| 42 | |
| 43 | ## NEVER Do in AutoLoad Architecture |
| 44 | |
| 45 | - **NEVER access AutoLoads in `_init()`** — AutoLoads are initialized sequentially. Accessing one in `_init()` may find a null reference [12]. |
| 46 | - **NEVER modify a Singleton's size or children in `_ready()`** — If multiple Singletons refer to each other's trees during boot, it can cause layout/sorting errors. |
| 47 | - **NEVER store highly localized, scene-specific data in AutoLoads** — This creates "God Objects" and introduces global side effects that are hard to debug [14]. |
| 48 | - **NEVER use `Parent.method()` calls from an Autoload** — Autoloads sit at the root. They are the ultimate "top". Use signals to talk to the active scene. |
| 49 | - **NEVER use an Autoload for pure data containers** — If you don't need `_process()` or signals, use a `static var` in a `class_name` script instead [7]. |
| 50 | - **NEVER create circular dependencies between Singletons** — If A needs B and B needs A, Godot will hang during the splash screen [13]. |
| 51 | - **NEVER free an Autoload node manually** — Removing a singleton from the root can leave dangling references that crash the engine. |
| 52 | - **NEVER use AutoLoads for UI elements that aren't global** — Popups that only exist in one level should be in that level, not a global singleton. |
| 53 | - **NEVER assume `get_tree().current_scene` is accurate in `_ready()`** — In Autoloads, the active scene might still be initializing. Access it via `get_tree().root.get_child(-1)` [6]. |
| 54 | - **NEVER skip `process_mode` configuration** — If your global console or music manager needs to work while the game is paused, set `process_mode = PROCESS_MODE_ALWAYS`. |
| 55 | |
| 56 | |
| 57 | --- |
| 58 | |
| 59 | ## When to Use AutoLoads |
| 60 | |
| 61 | **Good Use Cases:** |
| 62 | - **Game Managers**: PlayerManager, GameManager, LevelManager |
| 63 | - **Global State**: Score, inventory, player stats |
| 64 | - **Scene Transitions**: SceneTransitioner for loading/unloading scenes |
| 65 | - **Audio Management**: Global music/SFX controllers |
| 66 | - **Save/Load Systems**: Persistent data management |
| 67 | |
| 68 | **Avoid AutoLoads For:** |
| 69 | - Scene-specific logic (use scene trees instead) |
| 70 | - Temporary state (use signals or direct references) |
| 71 | - Over-architecting simple projects |
| 72 | |
| 73 | ## Implementation Pattern |
| 74 | |
| 75 | ### Step 1: Create the Singleton Script |
| 76 | |
| 77 | **Example: GameManager.gd** |
| 78 | ```gdscript |
| 79 | extends Node |
| 80 | |
| 81 | # Signals for global events |
| 82 | signal game_started |
| 83 | signal game_paused(is_paused: bool) |
| 84 | signal player_died |
| 85 | |
| 86 | # G |