UnityEvent errors in polymorphic lists

Issue #195 resolved
Former user created an issue

I'm using Unity 2017.1.0f3 on Windows 7. The about window for Odin is telling me 0.0.0.0 as the version, but I just imported Odin yesterday via the Unity project creation flow, so I believe it's 1.0.5.1. If there is some other way to tell, I can update it with that.

I cannot use a UnityEvent in a polymorphic list in a SerializedMonoBehaviour. It just creates an error in the display saying "Could not create an alias UnityEditor.SerializedProperty for the property 'm_event'".

I looked at some of your other bugs and for a similar one you suggest using DrawWithUnity, but that results in a different error in this case: "Could not get a Unity SerializedProperty for the property 'Event' of type UnityEvent' at path 'm_test.$0.m_event'."

The code below demonstrates the problem, just add it to a GameObject and add a UnityEventTest to the list.

using Sirenix.OdinInspector;
using Sirenix.Serialization;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;

[AddComponentMenu("Bug/Contained Unity Event Test")]
public class ContainedUnityEventTest : SerializedMonoBehaviour
{
    [System.Serializable]
    private abstract class TestBase
    {
    }

    [System.Serializable]
    private class UnityEventTest : TestBase
    {
        [OdinSerialize, HideReferenceObjectPicker]
        private UnityEvent m_event = new UnityEvent();
    }

    [OdinSerialize, HideReferenceObjectPicker]
    private List<TestBase> m_testList = new List<TestBase>();
}

Comments (2)

  1. Tor Esa Vestergaard
    • changed status to open

    Hello,

    Sorry for the late response - just came back from Unite Austin, and it's been a bit hectic. I've been playing around with this, and it's a case of Unity's own UnityEventDrawer acting very strange, and only working under very specific circumstances. Essentially, you must make sure that the UnityEvent is being serialized by Unity, not Odin, and that it is declared on a Component, not a ScriptableObject.

    For now, I will add a better error message telling the user this.

    Eventually, though, it looks like we will simply have to create our own UnityEventDrawer to properly resolve this.

  2. Log in to comment