What breaking changes would YOU make to Unity?

Here’s one: Stop keeping the value of non-public fields that aren’t marked with [SerializeField] after domain reload.

That behavior is not very well known by a lot of users, and it’s easy to forget once you know about it. It’s not too hard to go around it (just mark the field with [System.NonSerialized]), but it’s easy to miss a field, specially because only fields that are supported by Unity’s serialization system are affected.

Here are some reasons to remove this behavior:

  • In a world where we want to improve iteration time on script changes , this is some work that could be eliminated.

  • It causes weird inconsistencies. Fields supported by Unity keep their values and other fields don’t. Likewise, fields that would be expected to be null are initialized with an instance while other fields are kept null.

  • Removing it would mean less breaking changes if Unity adds support for other serialized types. Imagine they add serialization support for Dictionaries; it could make a lot of Dictionary fields that are expected to be initially null to be an empty dictionary instead in some cases.

  • It has no practical use. In the vast majority of code, one still has to handle the case where those fields are not deserialized by Unity. That’s because it doesn’t happen outside the editor, it doesn’t happen for Objects in the Scene after entering Play Mode when Scene Reloading is not disabled, and it doesn’t happen when restoring the Scene after exiting Play Mode (that results in disabling Scene Reloading causing more inconsistencies).

I really think this change could be made without causing much trouble. The only practical use for this that I can imagine is support for Domain Reload in the middle of Play Mode when a script changes. But changing scripts in the middle of Play Mode isn’t really supported anyway, because a lot of private fields that aren’t handled by Unity can’t be restored. Lots of Unity’s own systems don’t support it. That’s another breaking change I’d make: Remove the option of reloading scripts in the middle of Play Mode. Or at least don’t make it the default option in the settings.

5 Likes