- Home /
Unity keeps asking to save a scene
Every time I switch scenes int Unity, it will ask if I want to save the changes I've made to a scene, even though I didn't make any. I noticed this started happening after I updated. Could it just be a bug or could there be another reason?
Answer by eddyspaghetti · Oct 08, 2018 at 03:45 PM
I know this is a little old, but this has been happening to me in 2018.2.0f2. I registered a callback with the Undo system to try to figure out what's happening using the code below (in one of my editor classes). When I add this, I can see what undo-able changes are happening to the scene. In our case the issue is that Unity is making tiny changes to the anchor positions of the Handle game object for a scrollbar in our UI. It's stuff like:
"Changed value for target Handle:m_AnchorMin.y to 0.0000004172325 from 0.0000011324883"
I haven't figured out how to suppress tiny changes, but at least I've ruled out issues with our own code.
public static bool TrackSceneChanges = false;
public static void EnableSceneDirtyChecker()
{
if (!TrackSceneChanges)
{
Undo.postprocessModifications += OnPostProcessModifications;
TrackSceneChanges = true;
}
}
public static void DisableSceneDirtyChecker()
{
if (TrackSceneChanges)
{
Undo.postprocessModifications += OnPostProcessModifications;
}
}
public static UndoPropertyModification[] OnPostProcessModifications(UndoPropertyModification[] propertyModifications)
{
Debug.Log("Dirty!");
foreach (UndoPropertyModification mod in propertyModifications)
{
Debug.Log($"Changed value for target {mod.currentValue.target.name}:{mod.currentValue.propertyPath} to {mod.currentValue.value} from {mod.previousValue.value}");
}
return propertyModifications;
}
I have VSTS (souce control) in my project and I checked When I open my scene Unity immediately mark it as unsaved. If I save and then check in the source control what has changed it is the same thing: Some object's anchor changed from 0 to 0.0000324. And everytime I open the scene it keeps changing a few decimal values. This generates garbage to my project's source control all the time...
I still haven't found the reason that unity is doing/generating this floating values.. I'm using Unity 2018.2.5
Answer by OneCept-Games · Jan 05, 2018 at 04:10 PM
Could be that some Editor scripts are changing your scene objects. Do you have your own- or Asset Store purchased Editor scripts in your project?
I don't think so. I have downloaded a few things from the store but I think I've deleted them all because I don't use them anymore.
Could EditorUtility.SaveFilePanelInProject be causing the problem?
No build in Editor scripts should cause this. Speaking of saving a scene, i use this script to actually remember to always save on Play. It might help you in this case also, because then it saves automatically - at least on Play, and you might be able to change it to save on Close by using EditorScene$$anonymous$$anager.SceneClosingCallback. using UnityEngine; using UnityEditor; using UnityEditor.Scene$$anonymous$$anagement;
namespace OneCept {
[InitializeOnLoad]
public class SaveOnPlay
{
static SaveOnPlay()
{
EditorApplication.playmodeStateChanged += SaveCurrentScene;
}
static void SaveCurrentScene()
{
if (!EditorApplication.isPlaying && EditorApplication.isPlayingOrWillChangePlaymode)
{
//Debug.Log("Saving scene on play...");
EditorScene$$anonymous$$anager.SaveOpenScenes();
}
}
}
}
Answer by Thaun_ · Jan 05, 2018 at 04:52 PM
No, there isnt any bug with that. Lets say you havent changed anything, you think you havent changed anything, but Unity itself might have automaticly did tiny tiny changes that it needs to be saved. Dont worry, but we suggests that you keep saving it.
I just wish it wouldn't! Its very annoying when I have to switch between a few scenes and I keep getting the popup to save for each one
Answer by wlwl2 · Nov 07, 2018 at 07:06 PM
@caulfield85 @eddyspaghetti this bug (it is a bug!) happens on Unity 2018.1.5f1 as well. I guess that it has something to do with UI layout. For me the solution was to disable the child (with the layouts) in my root UI game object (I only use one UI canvas and have its children heavily nested). Something in that child is causing this issue I guess, I use layouts a lot inside it (it's a menu). I'll update my answer when I figure it out.
I have the same issue with 2019.1.0a9 with a canvas in the scene. It's annoying to keep discarding changes in my git
Answer by BV123 · Jan 24, 2020 at 11:05 PM
Layout->Revert Factory Settings->Restart Unity worked for me.