Two brits working in a basement made Construct 2 ten years ago, and while running on tea and fried fish, managed to implement an auto-save feature for their game-making software.
I just lost 2 hours of my time because this pig of a software decided to hang itself.
Why don’t I save often? Sorry but when I’m focused, I forget to babysit the editor.
Just found this plugin on the store, going to give it a try:
Unity actually does auto-save your scenes every time you enter play-mode and stores them in the Temp/__Backupscenes folder. These files are not meant to be used as a user-facing auto-save feature (I think Unity might use them to restore all your scene settings after exiting play-mode so play-mode changes don’t stick around) but it can be used in a pinch to restore your lost progress. Just remember that you need to copy those backup files before you re-open Unity after a crash as Unity wipes the Temp folder on launch.
I’m not downplaying it. But Unity takes their own sweet time to actually implement a feature. No matter how trivial it is. So in the meantime you should just implement it yourself.
You should also put in a feedback request and link it here. There is a slightly greater chance Unity will see the request there then in the forums.
Make a script called Autosave.cs and put it in a folder named “Editor”, with this in it:
using UnityEditor;
using UnityEditor.SceneManagement;
using UnityEngine;
[InitializeOnLoad]
public class Autosave
{
static Autosave()
{
EditorApplication.playmodeStateChanged += () =>
{
if (EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isPlaying)
{
Debug.Log("Auto-saving all open scenes...");
EditorSceneManager.SaveOpenScenes();
AssetDatabase.SaveAssets();
}
};
}
}
It will automatically save any time you press Play. This is the first thing I do in any project. I’m terrible at remembering to manually save.
And I agree with the OP, this should really be a built-in feature of Unity. It’s crazy that they don’t save automatically.
Updated for 2017.4 as it says playmodeStateChanged is obsolete.
using UnityEditor;
using UnityEngine;
using UnityEditor.SceneManagement;
[InitializeOnLoad]
public class AutoSave
{
// Static constructor that gets called when unity fires up.
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();
}
};
}
}
Oh wow. Today I learned my most used key combination (right after CTRL+ALT+DELETE - old statistic trash from WinXP days) is CTRL+S. It’s not even a habit I developed from Unity…
Just wanted to add a slightly better solution here. Add this as a script in the Editor folder and you’ll get a menu toggle that will allow users to choose if they want the autosave enabled:
using UnityEngine;
using UnityEditor;
using UnityEditor.SceneManagement;
[InitializeOnLoad]
public class AutoSaveOnRunMenuItem
{
public const string MenuName = "Tools/Autosave On Run";
private static bool isToggled;
static AutoSaveOnRunMenuItem()
{
EditorApplication.delayCall += () =>
{
isToggled = EditorPrefs.GetBool(MenuName, false);
UnityEditor.Menu.SetChecked(MenuName, isToggled);
SetMode();
};
}
[MenuItem(MenuName)]
private static void ToggleMode()
{
isToggled = !isToggled;
UnityEditor.Menu.SetChecked(MenuName, isToggled);
EditorPrefs.SetBool(MenuName, isToggled);
SetMode();
}
private static void SetMode()
{
if(isToggled)
{
EditorApplication.playModeStateChanged += AutoSaveOnRun;
}
else
{
EditorApplication.playModeStateChanged -= AutoSaveOnRun;
}
}
private static void AutoSaveOnRun(PlayModeStateChange state)
{
if (EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isPlaying)
{
Debug.Log("Auto-Saving before entering Play mode");
EditorSceneManager.SaveOpenScenes();
AssetDatabase.SaveAssets();
}
}
}
Thanks to all who post there solutions but I think unity has to implement an option to enable autosave when clicking on play. It is just one line of code
I just found out the hard way the ‘Save Project’ didn’t save, well, you know my project so I lost my scenes. I did wonder why there was a separate ‘Save Scene’ option !
Anyhow, your script is awesome and why this is not bundled with Unity is anybody’s guess.
Cheers
I’m not interested in this feature. I often make changes to experiment, and don’t want those saved until I say so specifically. It will be way more irritating to have to disable this feature any time I want to experiment than it is to just tell Unity to save when I want it to save.
I am not interested in this feature one bit. A. most of what we do in Unity is automatically saved. (unlike other engines that you need to save everything) B. It is extremely rare that any of the people I have known and any of the projects I have worked on, large and small, ever needed it.
Unity is rock solid compared to so many other tool out there. It is the most stable tool I have ever used. Even photoshop crashes more which is known to be rock solid.
So no, not really needed. Learn to save or create an editor tool that does it for you.
Nothing you do in Unity is automatically saved. Nothing at all. If you change the scene, you must save. If you change a prefab, you must save. If you change a material or a build setting, you must save. If you shut it down and don’t save, you lose every single change you made.
I often use this fact, by doing an experiment, and if I don’t like the results, I just reload without saving.