Search Unity

We NEED Auto-save feature

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

Thread Status:
Not open for further replies.
  1. PapitoMyKing

    PapitoMyKing

    Joined:
    Apr 25, 2016
    Posts:
    12
    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
     
  2. passerbycmc

    passerbycmc

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

    ScottyB

    Joined:
    Apr 4, 2011
    Posts:
    146
    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.
     
    C0descr1pt, Cynicat, GuyManj and 8 others like this.
  4. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    It's trivial to extend the editor to do this yourself.
     
  5. boxhallowed

    boxhallowed

    Joined:
    Mar 31, 2015
    Posts:
    513
    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.
     
  6. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    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,350
    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
  8. sarynth

    sarynth

    Joined:
    May 16, 2017
    Posts:
    98
    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,243
    Doesn't it already autosave when you press play?
     
  10. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    3,038
    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,243
    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:
    34
    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. }
     
    Two_Fifty, vlaskzBR, Yacine7 and 14 others like this.
  13. Kerosini

    Kerosini

    Joined:
    Aug 16, 2014
    Posts:
    13
    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. 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 by a moderator: 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?
     
    C0descr1pt likes this.
  17. Joe-Censored

    Joe-Censored

    Joined:
    Mar 26, 2013
    Posts:
    11,847
    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:
    589
    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:
    103
    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.
     
    warpfx, matronator, Balea and 6 others like this.
  20. Zaine7673

    Zaine7673

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

    Joe-Censored

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

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    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,350
    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
     
  24. DreamPower

    DreamPower

    Joined:
    Apr 2, 2017
    Posts:
    103
    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:
    589
    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)
     
  26. Rodolfo-Rubens

    Rodolfo-Rubens

    Joined:
    Nov 17, 2012
    Posts:
    1,197
    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...
     
    animat_, Thygrrr, Balea and 1 other person like this.
  28. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,782
    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 Deleted User like this.
  29. DGordon

    DGordon

    Joined:
    Dec 8, 2013
    Posts:
    649
    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
    animat_, C0descr1pt and sand_lantern like this.
  30. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    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.
     
    Balea and Joe-Censored like this.
  31. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,782
    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:
    649
    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 ^^.
     
    akinoreiki, animat_ and matronator like this.
  34. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,782
  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.
     
    animat_, matronator and StellarVeil like this.
  36. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,782
    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. 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,860
    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.
     
    matronator and Antypodish like this.
  39. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,782
    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,860
    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:
    3
    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:
    11,847
  43. AkshayVats

    AkshayVats

    Joined:
    Jun 19, 2013
    Posts:
    4
    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?
     
    animat_ and matronator like this.
  44. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,782
    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:
    4
    Works like a charm for Unity 2019.1
     
    linq and poliman like this.
  46. poliman

    poliman

    Joined:
    Feb 5, 2015
    Posts:
    29
    Script makes errors while compiling x86 in 2019.1.5
     
  47. wolilio

    wolilio

    Joined:
    Aug 19, 2019
    Posts:
    29
    should like Sublime Text's "auto save" ,it saves modified but unsaved file in somewhere else ,close then reopen sublime, unsaved file is still in a open tab
     
  48. drizztdourden_

    drizztdourden_

    Joined:
    May 4, 2016
    Posts:
    7
    I can't believe this is not a basis feature at this point. It is obviously really simple to implement considering the solutions given.

    Just add an effin checkbox next to the play button in unity "unchecked" by default. That's it. If checked, you save when you play, if not, you don't.

    End of story.
     
    animat_ likes this.
  49. fdp_san

    fdp_san

    Joined:
    Jun 22, 2017
    Posts:
    8
    ITT : Condenscending people
     
  50. sommmen

    sommmen

    Joined:
    Jan 7, 2016
    Posts:
    9
    version 2019.3.7f1 and the latest script works like a charm!
     
Thread Status:
Not open for further replies.