Skip to content

Instantly share code, notes, and snippets.

@mrcarriere
Last active November 17, 2016 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrcarriere/034ffde5ac162d11d997e7eebb2471de to your computer and use it in GitHub Desktop.
Save mrcarriere/034ffde5ac162d11d997e7eebb2471de to your computer and use it in GitHub Desktop.
Automatically save dirty scenes and assets as soon as you enter playmode.
using UnityEngine;
using UnityEditor;
using UnityEditor.SceneManagement;
[InitializeOnLoad]
public class SaveSceneOnPlay
{
static SaveSceneOnPlay()
{
EditorApplication.playmodeStateChanged += () =>
{
if (!EditorApplication.isPlaying && EditorApplication.isPlayingOrWillChangePlaymode)
{
Debug.Log("Autosaving dirty scenes and assets.");
EditorSceneManager.SaveOpenScenes();
AssetDatabase.SaveAssets();
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment