DWAutoLoad Node
DWAutoLoad Node
Persisted singleton state with minimal boilerplate
Base node for global state that should round-trip through SQLite using the same schema metadata as DWRecord.
Ideal for inventories, progression flags, or analytics caches that live in Autoload singletons.
Automatically mirrors exported properties into a backing table using the node name as the key.
Supports manual `save_to_db(wait = true)` calls when quitting or before scene transitions.
Usage patterns
Track campaign progress
@tool
class_name CampaignState
extends DWAutoLoad
@export var slot: int
@export var active_quest: String
@export var milestones: Array[String]
func _ready() -> void:
schema.table_name = "campaign_state"
schema.primary_key = "slot"
Flush changes when disconnecting
Wire the signal from DWService to guarantee your singleton state hits disk before shutdown.
func _on_DataWiz_disconnecting() -> void:
save_to_db(wait = true)
Key methods
- save_to_db(wait: bool = false) -> bool
Persists the node's exported properties into the associated table.
- load_from_db(where_clause: String = "", params: Dictionary = {}) -> bool
Reads the node's data back into exported properties using the schema metadata.
- from_dictionary(payload: Dictionary)
Hydrates the node using raw dictionary data—useful for manual query pipelines.
Operational tips
- Call `save_to_db(wait = true)` in response to `DWService.disconnecting` to avoid losing final changes.
- Pair with `DWService.register_table(self)` during startup when you need deterministic schema creation.