top of page

Autosave

Engine : Unity

Tools : Unity

Create periodic saves of the scene being worked on.

Script
Result
Screenshot from 2024-07-04 08-24-58.png
Explanation
The AutoSave tool automatically saves your open scene at configurable time intervals while you're working in the Unity Editor (not in Play mode). It creates timestamped backups in a dedicated folder inside your current scene’s directory.
Files Involved
There are 3 main scripts involved:
  1. AutoSave.cs
  2. AutoSaveScriptable.cs
  3. AutoSaveSettingsProvider.cs
AutoSave.cs – The Main Background Saver
This is the engine behind the auto-save functionality.
How it Works:
  • Marked with [InitializeOnLoad], which means it runs as soon as Unity loads the editor (no need to press play).
  • Registers a method (OnEditorUpdate) to Unity’s EditorApplication.update event – this runs every editor frame.
  • Checks:
    • If auto-save is enabled.​
    • If Unity is not playing, building, or compiling.
    • If the Unity editor window is currently active.
    • If the scene has a valid path.
  • If all is okay, it saves a copy of the scene into a subfolder named AutoSave, inside your current scene folder.​
  • Scene name will be something like:
    SceneName Mar 12-31pm.unity
Save Frequency:​
  • Controlled by AutoSaveScriptable.cs, default is every 5 minutes.
Logging:​
  • If Logging is enabled, it prints Auto-saved at XX in the console.
AutoSaveScriptable.cs – Config Data Storage
This script stores the configuration for auto-save.
Key Components:
  • ScriptableSingleton<AutoSaveScriptable> – this is Unity Editor's way of saving persistent config data.
  • AutoSaveConfig class:
    • Enabled: whether auto-save runs
    • Frequency: how many minutes between saves
    • Logging: whether to show messages in the console
Unity saves this config as a file:
Tools/Auto Save Config.volt
AutoSaveSettingsProvider.cs – Unity Project Settings UI
This adds a UI to Unity’s Project Settings under:
Project > Tools > AutoSave
What It Adds:
  • Toggle to enable/disable auto-save.
  • Integer field for save frequency (in minutes).
  • Toggle for logging.
Details:​
  • Uses Unity’s UI Toolkit (VisualElement, Toggle, IntegerField, etc.).
  • Whenever a field is changed, it updates the config and calls Save().
  • Mail
  • telephone
  • LinkedIn
bottom of page