Skip to content

Instantly share code, notes, and snippets.

@Marsgames
Last active March 24, 2021 10:05
Show Gist options
  • Save Marsgames/40635c471ea962dd55a7afac5348c385 to your computer and use it in GitHub Desktop.
Save Marsgames/40635c471ea962dd55a7afac5348c385 to your computer and use it in GitHub Desktop.
Put it in Assets/Editor. Automaticaly save scene every time you press play
using UnityEditor;
using UnityEngine;
using UnityEditor.SceneManagement;
[InitializeOnLoad, HelpURL("https://forum.unity.com/threads/we-need-auto-save-feature.483853")]
public static class AutoSave
{
/// <summary>
/// Static constructor that gets called when unity fires up.
/// </summary>
static AutoSave()
{
EditorApplication.playModeStateChanged += (PlayModeStateChange state) =>
{
// If we're about to run the scene...
if (EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isPlaying)
{
// Save the scene and the assets.
Debug.Log("Auto-saving all open scenes... " + state);
EditorSceneManager.SaveOpenScenes();
AssetDatabase.SaveAssets();
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment