Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

We NEED Auto-save feature

Discussion in 'Editor & General Support' started by PapitoMyKing, Jul 18, 2017.

  1. PapitoMyKing

    PapitoMyKing

    Joined:
    Apr 25, 2016
    Posts:
    10
    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:

    https://www.assetstore.unity3d.com/en/#!/content/90091
     
    kilik128, Circool, zeiksz and 4 others like this.
  2. passerbycmc

    passerbycmc

    Joined:
    Feb 12, 2015
    Posts:
    1,470
    save often and commit to a VCS problem solved
     
    leftshoe18 likes this.
  3. ScottyB

    ScottyB

    Joined:
    Apr 4, 2011
    Posts:
    132
    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.
     
    guetta18, phoda, Ryiah and 3 others like this.
  4. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,431
    It's trivial to extend the editor to do this yourself.
     
  5. The-Britain

    The-Britain

    Joined:
    Mar 31, 2015
    Posts:
    714
    Then, it's trivial for Unity to implement this. It's a necessary feature that everything from Word to Unreal 4 has. Don't downplay his request.
     
    tmendez, Sandsoft, zeiksz and 7 others like this.
  6. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,431
    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.
     
  7. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,298
    Make a script called Autosave.cs and put it in a folder named "Editor", with this in it:

    Code (csharp):
    1. using UnityEditor;
    2. using UnityEditor.SceneManagement;
    3. using UnityEngine;
    4.  
    5. [InitializeOnLoad]
    6. public class Autosave
    7. {
    8.     static Autosave()
    9.     {
    10.         EditorApplication.playmodeStateChanged += () =>
    11.         {
    12.             if (EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isPlaying)
    13.             {
    14.                 Debug.Log("Auto-saving all open scenes...");
    15.                 EditorSceneManager.SaveOpenScenes();
    16.                 AssetDatabase.SaveAssets();
    17.             }
    18.         };
    19.     }
    20. }
    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.
     
    Last edited: Jul 19, 2017
    baazul, Goat-Boy, Circool and 13 others like this.
  8. sarynth

    sarynth

    Joined:
    May 16, 2017
    Posts:
    16
    Updated for 2017.4 as it says playmodeStateChanged is obsolete.

    Code (CSharp):
    1. using UnityEditor;
    2. using UnityEngine;
    3. using UnityEditor.SceneManagement;
    4.  
    5. [InitializeOnLoad]
    6. public class AutoSave
    7. {
    8.     // Static constructor that gets called when unity fires up.
    9.     static AutoSave()
    10.     {
    11.         EditorApplication.playModeStateChanged += (PlayModeStateChange state) => {
    12.             // If we're about to run the scene...
    13.             if (EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isPlaying)
    14.             {
    15.                 // Save the scene and the assets.
    16.                 Debug.Log("Auto-saving all open scenes... " + state);
    17.                 EditorSceneManager.SaveOpenScenes();
    18.                 AssetDatabase.SaveAssets();
    19.             }
    20.         };
    21.     }
    22. }
    23.  
     
  9. FMark92

    FMark92

    Joined:
    May 18, 2017
    Posts:
    1,220
    Doesn't it already autosave when you press play?
     
  10. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    2,960
    After spending a few days with the latest beta, I think that is expecting too much ;)
     
  11. FMark92

    FMark92

    Joined:
    May 18, 2017
    Posts:
    1,220
    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...
     
  12. L42yB

    L42yB

    Joined:
    Dec 20, 2012
    Posts:
    6
    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:


    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEditor;
    3. using UnityEditor.SceneManagement;
    4.  
    5. [InitializeOnLoad]
    6. public class AutoSaveOnRunMenuItem
    7. {
    8.     public const string MenuName = "Tools/Autosave On Run";
    9.     private static bool isToggled;
    10.  
    11.     static AutoSaveOnRunMenuItem()
    12.     {
    13.         EditorApplication.delayCall += () =>
    14.         {
    15.             isToggled = EditorPrefs.GetBool(MenuName, false);          
    16.             UnityEditor.Menu.SetChecked(MenuName, isToggled);
    17.             SetMode();
    18.         };
    19.     }
    20.  
    21.     [MenuItem(MenuName)]
    22.     private static void ToggleMode()
    23.     {
    24.         isToggled = !isToggled;
    25.         UnityEditor.Menu.SetChecked(MenuName, isToggled);
    26.         EditorPrefs.SetBool(MenuName, isToggled);
    27.         SetMode();
    28.     }
    29.  
    30.     private static void SetMode()
    31.     {
    32.         if(isToggled)
    33.         {
    34.             EditorApplication.playModeStateChanged += AutoSaveOnRun;
    35.         }
    36.         else
    37.         {
    38.             EditorApplication.playModeStateChanged -= AutoSaveOnRun;
    39.         }
    40.     }
    41.  
    42.     private static void AutoSaveOnRun(PlayModeStateChange state)
    43.     {
    44.         if (EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isPlaying)
    45.         {
    46.             Debug.Log("Auto-Saving before entering Play mode");
    47.  
    48.             EditorSceneManager.SaveOpenScenes();
    49.             AssetDatabase.SaveAssets();
    50.         }
    51.     }
    52. }
     
  13. Kerosini

    Kerosini

    Joined:
    Aug 16, 2014
    Posts:
    12
    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 :)
     
  14. kaledbuilder

    kaledbuilder

    Joined:
    Feb 19, 2013
    Posts:
    1
    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
     
  15. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    4,138
    Rhetorical questions... why? Why is the <esc>:q!<enter> is the quit function in the Vi text editor? Because they designed it this way.
     
    Last edited: Dec 9, 2018
  16. nowletsstart

    nowletsstart

    Joined:
    Jan 1, 2016
    Posts:
    78
    This is very helpful. How can I update this script save a scene automatically whenever a change is made to the scene?
     
  17. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    5,954
    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.
     
    Xarbrough, Circool, Zaine7673 and 3 others like this.
  18. soleron

    soleron

    Joined:
    Apr 21, 2013
    Posts:
    87
    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.
     
    Xarbrough and Joe-Censored like this.
  19. DreamPower

    DreamPower

    Joined:
    Apr 2, 2017
    Posts:
    61
    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.
     
    nowletsstart likes this.
  20. Zaine7673

    Zaine7673

    Joined:
    Feb 15, 2018
    Posts:
    116
    If this is implemented it would be nice to have the option to switch it off.
     
    Xarbrough and Joe-Censored like this.
  21. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    5,954
    There's lots of things that save automatically, which I actually find fairly irritating.
     
    Kiwasi likes this.
  22. hippocoder

    hippocoder

    Digital Ape Moderator

    Joined:
    Apr 11, 2010
    Posts:
    25,331
    That's not correct. By default, prefabs do automatically save but there's a tickbox for that... :)
     
    Kiwasi and Charles-PAT like this.
  23. makeshiftwings

    makeshiftwings

    Joined:
    May 28, 2011
    Posts:
    3,298
    I still think it should be an option, of course not mandatory, for all those "experimenters" who really want an easy way to lose all their work and don't want to use Undo, saving a copy of a file, source control, backups, or any of the other many ways to revert stuff that you don't want to keep. ;)
    I want what you're smoking. :p
     
    Homicide and Kiwasi like this.
  24. DreamPower

    DreamPower

    Joined:
    Apr 2, 2017
    Posts:
    61
    I change prefabs all the time, the changes only get saved when I do a Save Project.
     
  25. soleron

    soleron

    Joined:
    Apr 21, 2013
    Posts:
    87
    Materials are saved automatically. Project settings too. If you change something on an asset any you apply it, it is saved, etc. etc. so yeah, most things (other than adding something in a scene or moving something, changing lighting etc.) do not get lost if you do not save your scene or project.

    What I would prefer instead of autosave, is something like Photoshop/Office where in a case of a crash your system holds the last state. (Not by autosaving the scene like in 3dsmax and Unreal)
     
    Joe-Censored, dziastiz and Circool like this.
  26. Rodolfo-Rubens

    Rodolfo-Rubens

    Joined:
    Nov 17, 2012
    Posts:
    1,094
    Same here, also, scriptable objects and most .asset files do not save unless you click save project.
     
  27. vladutstefan27

    vladutstefan27

    Joined:
    Sep 9, 2018
    Posts:
    5
    it's more than frustrating to lose 2 hours of level design because saving is the last thing you think about sometimes.
    The Editor crashed after I dragged and dropped an object that was already placed 30 times in the same scene.
    2 hours lost.
    Auto-save is more than needed.
    Give it a lil bit more time and even Paint.MS will have it, Jesus...
     
  28. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    5,139
    Ctrl+S / regular saving should become habit when appropriate. No excuses in IT world. That applies to any software.
    Same as making revisions and backups.
    Never happened since 1985, should it expect happen soon...? :)
     
    Kiwasi and APSchmidt like this.
  29. DGordon

    DGordon

    Joined:
    Dec 8, 2013
    Posts:
    396
    Pretty sure they arent discussing what they did wrong (forgetting to save) but a feature request for unity that would make sense for a lot of users (whether or not we all agree, need it, or care).

    Maybe lets keep the thread more on topic of asking unity to make a change for the better (or debating why its not better or how to find a solution everyone would like) :).
     
    Last edited: Jul 21, 2019
  30. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,431
    As long as there is a button to disable autosave, you can add it it. I've lost a lot of work over the years due to aggressive autosaves.
     
  31. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    5,139
    I suppose this is still valid 10 years later (since 2005).

    And for anyone interested
    https://forum.unity.com/search/95518199/?q=auto+save&t=post&o=date&c[title_only]=1

    There is noticeable tendency, that auto-save feature is requested, by fairly new devs.
    That means, such people are mostly not aware yet, of potential consequences / downsides of auto-saves.
     
    Last edited: Jul 22, 2019
    Joe-Censored likes this.
  32. DGordon

    DGordon

    Joined:
    Dec 8, 2013
    Posts:
    396
    Agreed. It would need to be blantant that its turned on or off. I wouldnt want it to save when I dont need it to (almost never, if ever) ... but I accept other peoples projects and needs might be better with it turned on ... theres a reason autosave is pretty standard in a lot of software.
     
  33. vladutstefan27

    vladutstefan27

    Joined:
    Sep 9, 2018
    Posts:
    5
    Don't really know about you, but when you're intensively working on a project, especially when it comes to level design, where you move, reposition, rotate the same object 100 times till it looks good, you really forget about saving. It just happens, and when it happens, oh boy, don't you regret it... Of course I regularly save my project's progress, but it really happens to forget about it.
    I still see auto-saving as a needed feature.

    Why do you think there's auto-save in tools like Photoshop, Illustrator, etc. ?
    Because you lose yourself in the work for hours and saving is the last thing u remind urself to do when you've already spent hours on editing the same image or creating it.

    Just give Paint.MS a little bit more time lol ^^.
     
  34. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    5,139
  35. vladutstefan27

    vladutstefan27

    Joined:
    Sep 9, 2018
    Posts:
    5
    imagine having to install a plugin for autosaving in Photoshop from github, then having to import it every time you create a new .psd file.
    But eh.
     
  36. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    5,139
    I save manually only, so I have no issue with that.
    But as many software, there are tons of plugins, which are optional. Some of these are essentials for others. And not part of default software package. Knowing such, only comes with an experience.

    However, I see you point, as you may dislike Unity approach, to install plugin per project, rather per Editor. I don't blame you for that.
    This is where I create a template with certain packages installed and use that for every next project. Saves lots of time, rather installing these packages every time, I create new project. Hope this may give you an idea. :)
     
  37. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    4,138
    I won't argue with the need or not need of auto-save, because I think this is crazy. You have a solution, you can use it. Would it be good to add an optional auto-save? Yes. Is it possible? I think as of now it is not. Saving is breaking the flow. It is a very resource-intensive thing to do. It's not one bitmap, which you just dump onto the disk, it's many files, many changes, many updates. Sometimes many GBs of data files involved.
    So while they develop something like this if they want, you have plugins.

    But, arguing with your PS-argument. You usually work on an image in PS for a couple of hours, maybe if you do really big work, a couple of days.
    A Unity Project is for months at best but more likely more than a year. So apples and oranges.
     
    Antypodish likes this.
  38. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,431
    Not really. All auto save would do is save the changes to the active scene. Scene files aren't that big. Changes to all other assets are handled by the program that creates them.

    From a technical standpoint auto save should be relatively simple to implement.
     
    Antypodish likes this.
  39. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    5,139
    Well, @Kiwasi got actually the point.
    In fact, certain files are saved at creation. Materials, textures, prefabs. Unless generating something in the editor.
    Scenes isn't that big itself, unless has tons of objects.

    However, when dropping on scene large number of objects, or heavy mesh wise, or some magic shaders, just for testing and then suddenly scene is saved, then it may be inconvenient to reopen that scene again and back to where it was. Sure repository etc ... for recover. But that tend to be after thought, after realizing mistake. Specially for new devs.

    Another aspect which is none-discoverable for tiny projects of new devs., when project grows, and Unity does auto refresh ever so often. For example saving. That can be a pain in back side, when Unity freezes each time. But can be turned off fortunately.

    Technically is just calling same method as ctrl+s, unless I am missing something?
     
    Joe-Censored and Kiwasi like this.
  40. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,431
    Not missing anything. Ctrl+S just saves the scene and the project settings. Nothing else. Everything else you create in Unity has its own explicit save button.
     
  41. matheusmatematica00

    matheusmatematica00

    Joined:
    Jul 28, 2019
    Posts:
    2
    guys, there a lot of editor folders, i dont know what is that i put the script
     
  42. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    5,954
  43. AkshayVats

    AkshayVats

    Joined:
    Jun 19, 2013
    Posts:
    1
    I like how people are defending Unity here. I love the IDE but we all have lost progress every once in a while. I have seen a lot of Brackeys where he mentioned that he lost progress due to Unity crash and he didn't save the scene. Now this is a person who is regularly working with Unity.

    Those who are saying that just install the plugin - well, I got the warning that the plugin uses obsolete code and unity crashed right away. Why pause with every project to find the right plugin which can later prove to be unreliable?

    It's impossible to implement save feature as it will involve lots of storage writes - make it optional? threads? priority?
     
  44. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    5,139
    Either you do save manually, or automatic, saves won't happens every change user makes. It is easier come back to work flow of thoughts, if you decided when to save, rather than some auto save, which saves you in random time of your workflow.

    Even when editor crashes, you remember when you Las time manually saved, and most likely, how to come back to the point, before crash. If you open autosave, you probably start to spend time and worry, at which point autosaved happened. Which changes have been saved and which did not.

    Therefore, manual and conscious save choices, is superior, over any auto save method. That if you value your own time of course.

    That applies to any software. Not only Unity.

    Fortunately in case of Unity, version control can be very useful tool, even during crash time.
     
  45. iamnexxed

    iamnexxed

    Joined:
    Jun 12, 2019
    Posts:
    1
    Works like a charm for Unity 2019.1
     
    poliman likes this.
  46. poliman

    poliman

    Joined:
    Feb 5, 2015
    Posts:
    14
    Script makes errors while compiling x86 in 2019.1.5