Unity crashes when trying to put non serializable class in list

Issue #148 resolved
Timo Ohr created an issue

Setup is essentially like this:

  • A SerializedScriptableObject with a serialized list containing some class

  • Said class is not marked as Serializable

  • When trying to add a new element in the list inspector of the scriptable object Unity crashes

Example code:

    [CreateAssetMenu(fileName = "Test", menuName = "Test")]
    public class TestObject : SerializedScriptableObject {
        [SerializeField]
        private List<TestClass> _test = new List<TestClass>();
    }

    public class TestClass {

    }

It does work when TestClass is properly marked as Serializable, but I keep forgetting to do that for some probably good reason. Should probably contain some check for whether the class is Serializable, and show and error / do nothing otherwise.

Using Unity 2017.1.0f3 with .NET 4.6, Odin Version 1.0.3.0

Comments (3)

  1. Tor Esa Vestergaard
    • changed status to open

    Thanks for reporting this - I just replicated it, and will be looking into what's going on promptly. The new experimental scripting backend has proven to be extremely temperamental, but hopefully this is one of the issues we can fix on our end, rather than having to wait on Unity.

    I'll let you know how it goes.

  2. Tor Esa Vestergaard

    Alright, I've figured this one out and fixed it. This happened when Odin was generating a serialization formatter for a type with no members to serialize. Apparently certain things about emitting have become mighty more fragile in the new experimental scripting runtime, and the empty IL code we emitted for the formatter, rather than doing nothing (as it should, working perfectly on the old runtime), just outright crashed Unity instead.

    The fix, at least, was a very simple one. Also, you'll find that if you add a serialized member to TestClass, everything will work just fine for now.

    If getting the fix for this bug is very important for you, you can email me at tor@sirenix.net with your invoice number, and I'll send you a build with the fix included.

    Cheers!

  3. Timo Ohr reporter

    Thank you for the quick fix, can confirm that this seems to have been the issue. I could swear I saw it working without having members, but can't replicate that anymore, so I'll file that under "faulty memory".

    I intend to stick it out for now with the new runtime, if I find any more issues I'd be happy to report it here.

    Cheers

  4. Log in to comment