Skip to content

Instantly share code, notes, and snippets.

@mrcarriere
Last active November 17, 2016 14:20
Show Gist options
  • 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