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

Scripts in different assemblies not resetting variables default values between runs in 2020.3

Discussion in 'Editor & General Support' started by push-pop, Mar 17, 2021.

  1. push-pop

    push-pop

    Joined:
    Jun 29, 2017
    Posts:
    28
    Hello! I've come across what seems to be a pretty massive issue and I'm having trouble understanding what is going on, but it is breaking my package.

    This only appeared in 2020.3 I have no issues in 2019.4. I am currently downloading 2020.2.7 to see if it is present there.

    What it SEEMS to me is happening is that script variables are not being reset to their default values. For example, I am using the Singleton class from the Unity Wiki Here which no longer works.
    https://wiki.unity3d.com/index.php/Singleton

    In particular m_ShuttingDown does not get reset to false, so all my singletons are returning null after the first run.


    It gets weirder. I am running the same code just fine in my repo, but when it is pulled in as a package is when it breaks. When I move that same code from the package folder to the Assets folder, it's still broken.

    I thought maybe it had to do with being in a different assembly but that is the case when it is in my repo as well.

    I really don't even know how to ask this question but it is totally breaking something that I use A LOT so any advice on what might be happening would be amazing. I'm stumped.
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,711
    The answer to this might be related to domain reloading:

    https://docs.unity3d.com/Manual/DomainReloading.html

    For non-static variables in ScriptableObject instances that you do NOT want to persist, always mark them [NonSerialized]:

    Code (csharp):
    1.     [NonSerialized] private    string    TheData;
    Without that decorator attribute, if this field was in a ScriptableObject instance, it would persist until you close the editor. This can be disastrous if for instance it was your
    bool initialized;
    field.
     
  3. push-pop

    push-pop

    Joined:
    Jun 29, 2017
    Posts:
    28
    Ahh yes thanks. For some reason the user had Enter Play Mode options checked but not Domain Reloading. Simply disabling that option fixed it.

    Project Settings > Editor:

    upload_2021-3-18_10-15-20.png
     
    Kurt-Dekker likes this.