Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Why does Editor backup non dirty scenes when entering play mode?

Discussion in 'Editor & General Support' started by Ghat-Smith, Sep 20, 2022.

  1. Ghat-Smith

    Ghat-Smith

    Joined:
    Aug 16, 2016
    Posts:
    48
    I have a big scene and I wanted to check if I could make entering play mode faster.
    After a look using editor deep profile, I've noticed a big part of the time spent was due to all the scenes being saved when you enter play mode: EnterPlayMode > EditorSceneManager.BackupScenes > SaveScene

    If I'm right, Unity creates a backup of all the opened scenes in the hierarchy, in order to restore those backups when you exit play mode. Correct me if I'm wrong but if the scene opened in the hierarchy is not dirty, it means its state is the same as the saved .unity scene asset. In this case, creating a backup seems totally useless, as the scene state could be restored using directly the .unity saved asset.

    Maybe I'm missing something, but I see here a potential huge enter play mode optimization.
    Sometimes you open a scene in the editor and you directly enter play mode without making any changes.
    And more often, you open multiple additive scenes, but work only on one of those. If I open 6 additive scenes, and changed only one, why would Unity create backups for the 5 others scenes on entering play mode?

    Going even further, when you exit play mode, could it be possible to skip reloading of scenes which have not been changed during play mode? (if assembly and scene reload have been disabled in
    Configurable Enter Play Mode options of course). Not really sure about this one, as reloading may be required to ensure proper cleanup.

    Note: behaviour noticed on Unity 2020.3.38f1 and Unity 2021.3.5f1


    EDIT: from the documentation
    This makes more sense to me, so I guess what I noticed is a bug.
    Made a bug report (IN-17264).
     
    Last edited: Sep 20, 2022
  2. Trindenberg

    Trindenberg

    Joined:
    Dec 3, 2017
    Posts:
    378
    The feature of Unity that most annoyed me is how changes arent saved when exiting playmode. There should at least be some option for saving/recording changes without using plugins ie. Save state/record icon button on everything to choose to save it.
     
  3. Ghat-Smith

    Ghat-Smith

    Joined:
    Aug 16, 2016
    Posts:
    48
    Yes, though it's a different topic. It's something that Unity team has considered for sure (it has been implemented in a really basic way for Cinemachine). I think it's somewhere on the roadmap too, but I hope you are patient.


    Regarding the backup scene issue, my bug report has been confirmed and is now in Unity Issue Tracker:
    https://issuetracker.unity3d.com/is...aves-non-dirty-scenes-when-entering-play-mode

    I hope it will be fixed quickly (and backported to LTS). Feel free to vote on this issue.
    Entering play mode quickly is very important in terms of productivity.
     
  4. Ghat-Smith

    Ghat-Smith

    Joined:
    Aug 16, 2016
    Posts:
    48
    Some news.

    From what I understand they tried to add a "Scene Backup" option in the fast enter playmode optimization.
    But as you can see in the bug report, it seems to "creates too many edge cases where it doesn't work correctly if skipped". So they are removing this option, and marked the issue as... "Duplicate" (why not "Won't Fix" I don't know).

    The "Duplicate Issue" is in fact a bug report (losing selection in hierarchy when entering play mode), and based on the resolution note the issue was caused by the "Scene Backup" option. And that I don't understand. Why skipping saving scenes which are already saved on the disk could cause issues related to hierachy selection ? That really doesn't make sense to me... but I guess I miss something here.

    I hope I could get some real explanations.
    For projects using additive scenes the scene backup optimization would be huge gain in terms of productivity. But sure if it creates too many edge cases I would understand this not being implemented. I would just like to have a concrete example of a problematic case because again, I really don't understand how skipping a useless operation (saving a file already saved on disk) could create issues.