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

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.

The answer to this might be related to domain reloading:

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

    [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.

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:

6949337--817424--upload_2021-3-18_10-15-20.png

1 Like