Skip to content

Instantly share code, notes, and snippets.

@andyman
Created March 1, 2018 03:56
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 andyman/d4f392510fb94a91d7cbf00fab7a13be to your computer and use it in GitHub Desktop.
Save andyman/d4f392510fb94a91d7cbf00fab7a13be to your computer and use it in GitHub Desktop.
Automatically save the Unity scene when pressing play.
// Place inside your Editor folder inside of Assets for it to save the current scene(s) when you run.
// The folder must be called "Editor", but can be nested within something else, e.g. Scripts/Editor
using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditor.SceneManagement;
[InitializeOnLoad]
public class OnUnityLoad
{
static OnUnityLoad()
{
EditorApplication.playModeStateChanged += (PlayModeStateChange change) =>
{
if (EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isPlaying)
{
Debug.Log("Auto-Saving scene(s) before entering Play mode.");
EditorSceneManager.SaveOpenScenes();
AssetDatabase.SaveAssets();
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment