The Save System is a comprehensive solution for managing game saves, providing features for creating, loading, and managing save files with support for auto-saves.
- 💾 Flexible Save Management: Create, load, and delete save files
- 🔄 Auto-save Support: Configurable automatic saving
- 📁 Custom Save Locations: Configurable save directory and file extensions
- 🔌 Component-based Serialization: Easy integration with game objects
- 🛡️ Async Operations: Non-blocking save/load operations
- ⚙️ Project Settings Integration: Configurable through Godot's project settings
var save_manager = CoreSystem.save_manager# Create a serializable component
class_name PlayerData
extends SerializableComponent
func serialize() -> Dictionary:
return {
"position": owner.position,
"health": owner.health,
"inventory": owner.inventory
}
func deserialize(data: Dictionary) -> void:
owner.position = data.position
owner.health = data.health
owner.inventory = data.inventory
# Register the component
save_manager.register_serializable_component($PlayerData)# Create a save
save_manager.create_save("save_001", func(success: bool):
if success:
print("Save created successfully!")
)
# Load a save
save_manager.load_save("save_001", func(success: bool):
if success:
print("Save loaded successfully!")
)
# Delete a save
save_manager.delete_save("save_001", func(success: bool):
if success:
print("Save deleted successfully!")
)# Enable auto-save
ProjectSettings.set_setting("save_system/auto_save_enabled", true)
ProjectSettings.set_setting("save_system/auto_save_interval", 300) # 5 minutes
ProjectSettings.set_setting("save_system/max_auto_saves", 3)
# Create auto-save manually
save_manager.create_auto_save()| Setting | Description | Default |
|---|---|---|
| save_directory | Directory for save files | "user://saves" |
| save_extension | File extension for saves | "save" |
| auto_save_enabled | Enable auto-save | true |
| auto_save_interval | Interval between auto-saves (seconds) | 300 |
| max_auto_saves | Maximum number of auto-saves | 3 |
Core class for managing save operations.
save_directory: String: Directory where saves are storedsave_extension: String: File extension for save filesauto_save_interval: float: Time between auto-savesmax_auto_saves: int: Maximum number of auto-savesauto_save_enabled: bool: Whether auto-save is enabled
create_save(save_name: String, callback: Callable) -> void: Create a new saveload_save(save_name: String, callback: Callable) -> void: Load an existing savedelete_save(save_name: String, callback: Callable) -> void: Delete a savecreate_auto_save() -> void: Create an auto-saveregister_serializable_component(component: SerializableComponent) -> void: Register a component for serializationunregister_serializable_component(component: SerializableComponent) -> void: Unregister a component
save_created(save_name: String): Emitted when a save is createdsave_loaded(save_name: String): Emitted when a save is loadedsave_deleted(save_name: String): Emitted when a save is deletedauto_save_created: Emitted when an auto-save is createdauto_save_cleaned: Emitted when old auto-saves are cleaned up
Base class for components that can be saved.
serialize() -> Dictionary: Convert component state to dictionarydeserialize(data: Dictionary) -> void: Restore component state from dictionary
-
Component Organization
- Keep serializable components focused and single-purpose
- Use clear naming conventions for save files
- Clean up old saves periodically
-
Error Handling
- Always check callback success status
- Provide fallback behavior for failed loads
- Handle corrupted save files gracefully
-
Auto-save Usage
- Set appropriate intervals based on game type
- Consider player progress and checkpoint frequency
- Clean up old auto-saves regularly
-
Performance
- Use async operations for large saves
- Optimize serialized data size
- Batch multiple saves when possible
-
Save Fails to Create
- Check write permissions
- Verify save directory exists
- Ensure valid save name format
-
Load Operation Fails
- Verify save file exists
- Check file permissions
- Validate save data format
-
Auto-save Issues
- Check auto-save settings
- Verify available disk space
- Monitor auto-save performance impact