Null references are assigned with a default instance after scripts have reloaded

Issue #283 resolved
Nicolás Ezcurra created an issue

When a field serialized by Odin is set to null and the project recompiles, it's assigned a new instance instead of staying as null.

Before reload:


After reload:


Comments (4)

  1. mSkull001

    I believe this is caused by Unity will serialize any field not marked with NonSerialized before a reload. Fx so that a game state can be kept. After the reload Unity will then deserialize these fields, and add a default value to them because Unity doesn't support null values in serialization.

    To get around this just add the NonSerialized attribute along with the OdinSerialize attribute to stop Unity from serializing the fields between reloads. You can also remove the Serializable attribute from the class definition, as Unity won't serialize it classes without that attribute either, but Odin will.

  2. Log in to comment