Automatically set default constructed values for fields on creation instead of null

Issue #63 resolved
Former user created an issue

When adding new SerializedMonoBehaviour components in the editor I have noticed all [OdinSerialize] fields with class types are initially set to null and not the default constructor value. This makes it tedious to go through these fields and select the non-null version yourself. I think it would be a better setup to go ahead and set the fields to the default constructor value instead of null. That's what Unity does by default. Being able to set fields to null is a huge advantage but it's far more common to actually want the object there.

Comments (1)

  1. Bjarke Elias

    Thanks for your feedback!

    You can achieve this just by assigning default values to your fields like this:

    public class MyComponent : SerializedMonoBehaviour
        public MyClass InstancedByDefault = new MyClass();
        public MyClass NullByDefault;
    public class MyClass
  2. Log in to comment