Last active
November 16, 2023 11:39
-
-
Save gaypunkposer/89baa0169354a18bb5347270775309f3 to your computer and use it in GitHub Desktop.
Unity auto save script. Throw in Assets/Editor. Saves assets and scene when playing a scene.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Works on Unity 5.3+ | |
using UnityEditor; | |
using UnityEditor.SceneManagement; | |
[InitializeOnLoad] | |
public class AutoSave | |
{ | |
//Constructor called by Unity Editor | |
static AutoSave() | |
{ | |
EditorApplication.playModeStateChanged += SaveWhenExitEdit; | |
} | |
private static void SaveWhenExitEdit(PlayModeStateChange change) | |
{ | |
//If we're exiting edit mode (about to play the scene) | |
if (change == PlayModeStateChange.ExitingEditMode) | |
{ | |
//Save the scene and the assets | |
EditorSceneManager.SaveOpenScenes(); | |
AssetDatabase.SaveAssets(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment