Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Editor freezes during scene/project save

Discussion in '2018.3 Beta' started by KazenoZ, Sep 22, 2018.

  1. KazenoZ

    KazenoZ

    Joined:
    Jan 24, 2015
    Posts:
    8
    So I've been working with the beta on a daily basis with my team since the day it launched.
    In my eyes, the risk of beta minuscules to the benefit we get from the new prefab workflows, so we went ahead with it. While keeping a safe copy on git, of course.

    Overall, the experience had been wonderful. I personally love everything about the new prefab workflows.
    However, we've been having some recurring problems with editor freezing during scene/project saving.

    I couldn't quite find a way to replicate it on a fresh project, and I still have a small hunch feeling that it may be caused by the fact that we upgraded from 2018.2, and the project wasn't freshly made in 2018.3, but what bothers me is that 2+ weeks later I'm still unable to find anyone else complaining about similar issues.

    The problem is that sometimes when I try to save, the saving spinner would just go on forever.
    In the beginning we really couldn't get any work done because of this, but then we found that if we force Unity to recompile by changing any script, then saving would go smoothly afterwards.

    Today I found a few instances of this issue that weren't solvable by recompiling, neither of which I could reproduce in a clean project, but they're reproducible in mine every single time, making it impossible to edit some scenes, so while I can't file a bug report, I'm hoping maybe someone here might have an idea.


    1. The first occurrence of this is regarding ScriptableObjects:
    upload_2018-9-22_19-18-7.png

    I have a pretty barebones scene in which I have a toggle that, once toggled, I want to change a setting in my scriptable object.
    Saving the scene works fine UNTIL I drag the scriptable object marked in red into the UnityEvent target field marked in red.
    If I try to save the scene once the scriptable object is assigned, even before selecting a function, the editor would freeze.


    2. The 2nd seems to do with the new prefabs in some way.
    upload_2018-9-22_19-20-50.png
    I created a new scene and saved it, and it saved fine.
    Then, I can change anything I want in it and add any objects and it saves fine, but if I try to add a prefab to the scene and save it, the editor would freeze during saving.
    Even completely unpacking the prefab and then trying to save will end up freezing the editor.
     
  2. KazenoZ

    KazenoZ

    Joined:
    Jan 24, 2015
    Posts:
    8
    So I ran a few more tests after using this post as a way for rubber ducking myself, and I eventually found something.

    Is it possible that the way OnValidate works had changed in 2018.3 relative to 2018.2 backwards?
    What seemed to have caused the freeze was an OnValidate call on a script on the CatPlayer object in the 2nd picture above.

    This is the relevant code
    Code (CSharp):
    1.     [SerializeField]
    2.     [Range(0, 999)]
    3.     private float m_Damage;
    4.     public float Damage
    5.     {
    6.         get { return m_Damage; }
    7.         private set
    8.         {
    9.             if (m_Damage != value)
    10.             {
    11.                 m_Damage = value;
    12.  
    13.                 if (Rigidbody) { Rigidbody.mass = m_DamageToMassRatio.Evaluate(value / 100); }
    14.  
    15.                 OnDamageChanged?.Invoke(value);
    16.             }
    17.         }
    18.     }
    19.  
    20.     private void OnValidate()
    21.     {
    22.         Damage = m_Damage;
    23.     }
    What fixed the bug for me is the line that says
    Code (CSharp):
    1. if (m_Damage != value)
    .
    It seems like in this version of Unity, OnValidate gets called even when the values on the object changed to the same values they were before. Or maybe it's some floating point math shenanigans. Beats me.
    So it was probably entering an infinite loop on validating.

    What's weirder though, is that debugging this showed that the OnValidate call was being called on another object altogether.



    I'll explain:

    In my game I have a few animal characters that the player can play, and the end goal of each stage is basically a small farm full of the playable characters welcoming you home.
    upload_2018-9-22_20-22-54.png
    The selected character in the picture above is the cat player for example.

    This WinZone object is a prefab that nests overrides of each of the playable characters, removing their interactivity scripts (i.e. Input scripts)

    The cat player from the original post is another override of the original playable cat player that I want to use with Timeline on some cutscene, so I made another instance override of it that removes the interactivity scripts and saved it in the cutscene's scene.

    When the OnValidate method is called on the cat in the cutscene scene, it seems like it then causes all the animals in the WinZone prefab to run their OnValidate methods as well, even though that prefab isn't even present at the scene.


    The same thing seemed to occur in the ScriptableObject case from the original post, since the GameSessionManager ScriptableObject holds a reference to the original CatPlayer prefab.
    upload_2018-9-22_20-27-23.png



    That being said, I still couldn't replicate this on a fresh project, probably because of the weird interaction with the unrelated prefab that I don't quite understand yet.
     
  3. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    3,135
    Thanks for sharing your findings with us KazenoZ,
    It would be very helpful if you could submit a bug report for the issues you're experiencing with reproduction steps. Even if submitting your project is not a possibility for you, that would ensure that someone will have a look at it.
     
  4. KazenoZ

    KazenoZ

    Joined:
    Jan 24, 2015
    Posts:
    8
    I can't replicate it anymore on my side since adding the check in the OnValidate method. I'll see if I can find a way to re-replicate it.

    However, I did run into a similar issue with Timeline, though it crashes instead of freezing, and doesn't seem to be related to OnValidate. I submitted a bug report using my project, since I couldn't replicate it in an empty project either. The Case ID is 1084656
     
    LeonhardP likes this.
  5. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    3,135
    Thank you, much appreciated!
     
  6. KazenoZ

    KazenoZ

    Joined:
    Jan 24, 2015
    Posts:
    8
    Seems to be fixed with the 2018.3.0b3 release that came today :)
     
    LeonhardP likes this.
  7. LeonhardP

    LeonhardP

    Unity Technologies

    Joined:
    Jul 4, 2016
    Posts:
    3,135
    Good to hear this issue is solved for you :)
     
  8. net8floz

    net8floz

    Joined:
    Oct 21, 2017
    Posts:
    37
    I seem to be experiencing a similar issue in regards to prefab variants trigger on validate and entering a loop on save. I haven't quite figured out everything that's happening. If I do I'll submit a bug report but I'd like to be sure it's not something I'm doing. using 0b5
     
    LeonhardP likes this.