Search Unity

Bug How to save everything? I can't reliably save things.

Discussion in 'Editor & General Support' started by mortoray, Dec 30, 2022.

  1. mortoray

    mortoray

    Joined:
    Sep 14, 2018
    Posts:
    94
    I'm having a problem in the editor that saving isn't working (I'm using the Linux version). I can see a "*" in the title bar indicating I have unsaved "something". I Press Ctrl+S and nothing happens. I choose "File | Save Project" and the star doesn't go away.

    When I exit I get asked if I want to save, but sometimes that doesn't save everything. As this morning I reopened my project and something I did last night is gone.

    Places like the UI Builder also don't appear to have a save option. I have no choice but to close the window and say "Yes" to wanting to save.

    This is driving me crazy, and leading to data loss. How can I reliably get everything to save?

    Version:
    2022.2.1f1.112.6257
    Revision: 2022.2/release 4fead5835099
    Built: Thu, 08 Dec 2022 14:15:26 GMT
     
    BYKD0 likes this.
  2. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    This has happened to me before, and the result has been some script running in edit mode that modifies a value of something in the scene. So, your scene is probably getting saved, but then some other code is immediately modifying something in the scene, causing the "*" to show up again.

    As for actually tracking that down... Version control might tell you if a value has changed? Look for scripts in your scene with ExecuteInEditMode on them, to see if they're modifying a value?
     
  3. mortoray

    mortoray

    Joined:
    Sep 14, 2018
    Posts:
    94
    I couldn't find anything with ExecuteInEditMode (did a file search on my Assets tree).

    I can confirm two clearer steps that don't save correctly:

    - If I'm modifying a scene, they press play, then close the editor I do not get a prompt to save -- I simply lose the changes
    - I edit a scene, then start editing a prefab, there is no option to save the other scene. Ctrl+S, Save Project, none of them change the other scene
    - If I then try to close, in edit mode, it allows me to save

    This leaves me with no safe way to close the app. :(
     
  4. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    Hmm. It kind of sounds like everything's working as expected, actually.

    Regarding your first item, about closing while in Play mode, that's expected. Nothing is saved if you're in Play mode. Any changes you make in play mode are 100% lost. And the scene won't necessarily show an "*" in those cases, as it won't consider the scene to have changes if it's in play mode.

    Regarding editing a prefab, if you have changes to your scene, then you open a Prefab to edit it, saving the prefab will not save the changes to your scene as well. When in Prefab editing mode, saving only saves the prefab. Only after leaving prefab mode will you be able to save the scene.

    But if you're editing the scene itself, and saving doesn't do anything, I'd check to make sure you have write permission on the directory the scene is in. Create a text file there as a test, and edit it. Make sure you can actually write to that directory.
     
  5. mortoray

    mortoray

    Joined:
    Sep 14, 2018
    Posts:
    94
    I'm not making changes in play mode, the changes were made outside of play mode. It's just once in play mode there appears to be no way to save the changes, and exiting the editor will lose those changes.

    I can understand that saving in a prefab saves the prefab, but isn't there a "Save All" option? Is there actually a way to "exit prefab mode" other than finding a scene and opening it?
     
  6. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,196
    What version of Unity are you on? Here's what it looks like when I edit a prefab. I can just click the little arrow to get out of prefab edit mode, and back to the normal scene:

    upload_2022-12-30_21-14-18.png

    Also, entering play mode when you have unsaved changes in the scene is risky. I know that's kind of what this is all about, but you should ideally ensure you're saving every time before entering play mode, unless you are okay with losing changes due to crashes.

    So, the question remains: Are you Edit Mode changes actually saving. I'd test the following:
    • Open a scene, any scene, in your project.
    • Add a new cube to it. Doesn't matter where, as long as you can tell it's there.
    • Save the project. (Ctrl-S, or File->Save)
    • Close Unity.
    • Reopen Unity. See if that Cube is still in the scene.
    If that cube is still there, then saving is working.
     
  7. mortoray

    mortoray

    Joined:
    Sep 14, 2018
    Posts:
    94
    Thanks, I don't think I would have seen that little arrow there, or known what it does. I can leave the Prefab mode.

    Yes, things are saving if I'm in the main scene. I suppose I'm just not used to not being able to save whenever.

    I'm not intentionally running without saving. But if I'm working on a prefab, there's no way to run without saving, unless, as you showed, I first leave the prefab, save then run. But then I have to renter the prefab if that's what I'm working on.
     
  8. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,744
    It sounds an awful lot like you are not properly using source control. You are one millisecond from complete disaster in this case, and NOBODY in the year 2022 (nearly 2023) should be forced to live like this.

    Please consider using proper industrial-grade enterprise-qualified source control in order to guard and protect your hard-earned work.

    Personally I use git (completely outside of Unity) because it is free and there are tons of tutorials out there to help you set it up as well as free places to host your repo (BitBucket, Github, Gitlab, etc.).

    You can also push git repositories to other drives: thumb drives, USB drives, network drives, etc., effectively putting a complete copy of the repository there.

    As far as configuring Unity to play nice with git, keep this in mind:

    https://forum.unity.com/threads/prefab-links-keep-getting-dumped-on-git-pull.646600/#post-7142306

    I usually make a separate repository for each game, but I have some repositories with a bunch of smaller test games.

    Here is how I use git in one of my games, Jetpack Kurt:

    https://forum.unity.com/threads/2-steps-backwards.965048/#post-6282497

    Using fine-grained source control as you work to refine your engineering:

    https://forum.unity.com/threads/whe...grammer-example-in-text.1048739/#post-6783740

    Share/Sharing source code between projects:

    https://forum.unity.com/threads/your-techniques-to-share-code-between-projects.575959/#post-3835837

    Setting up an appropriate .gitignore file for Unity3D:

    https://forum.unity.com/threads/removing-il2cpp_cache-from-project.1084607/#post-6997067

    Generally setting Unity up (includes above .gitignore concepts):

    https://thoughtbot.com/blog/how-to-git-with-unity

    It is only simple economics that you must expend as much effort into backing it up as you feel the work is worth in the first place. Digital storage is so unbelievably cheap today that you can buy gigabytes of flash drive storage for about the price of a cup of coffee. It's simply ridiculous not to back up.

    If you plan on joining the software industry, you will be required and expected to know how to use source control.

    "Use source control or you will be really sad sooner or later." - StarManta on the Unity3D forum boards
     
  9. mortoray

    mortoray

    Joined:
    Sep 14, 2018
    Posts:
    94
    @Kurt-Dekker I don't know how source-control factors into this discussion. It's irrelevant which tool I'm using (git) if the environment isn't saving when I expect it to save.
     
  10. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,744
    That's not true. The first file you make (right-click make C# file), exit Unity and add it to your source control... IMMEDIATELY.

    Whoa, wait, the file isn't there?!!!!

    Don't write another character until you figure out what is wrong.

    As I said, it only makes ECONOMIC sense to work without backing up if you value your work at $0.
     
    Last edited: Jan 2, 2023