Hello all,
I’ve been struggling today with this issue and hopefully someone here can help me.
So, I have a class derived from a ScriptableObject.
[System.Serializable]
public class CharacterSlot : ScriptableObject
{
public void OnEnable()
{
hideFlags = HideFlags.DontSave;
}
}
And after that I have another class derived from CharacterSlot
[System.Serializable]
public class InheritedSlot : CharacterSlot
{
}
In another scriptable object (which I actually save as an asset) I have a list of character slots:
public class CharacterSystem : ScriptableObject
{
public CharacterSystem parent = null;
public List<CharacterSlot> slots = new List<CharacterSlot>();
}
Now, I have custom property drawers for all these classes:
[CustomPropertyDrawer(typeof(CharacterSlot), false)]
public class CharacterSlotDrawer : PropertyDrawer
[CustomPropertyDrawer(typeof(InheritedSlot))]
public class InheritedSlotDrawer : PropertyDrawer
[CustomPropertyDrawer(typeof(CharacterSystem))]
public class CharacterSystemDrawer : PropertyDrawer
The issue is that when iterating over the slots and calling PropertyField, it won’t call the property drawer for the InheritedSlot. In fact for some reason it won’t even be compiled in since visual studio keeps saying that the breakpoints will never reach. Instead, it will always use custom property drawer for the CharacterSlot class (even though I specifically set the useForChildren flag to false). If I remove this property drawer and only keep the one for the InheritedSlot it will draw a list with every element set to “Type mismatch”.
I naturally did a bit of digging and I notice that all the properties have the type set to “PPtr<$CharacterSlot>” which might be fine given the fact that this type is given by the list property (I’m guessing here). The objectReferenceValue does contain a value of the InheritedSlot and yet the PropertyDrawer is the one for the CharacterSlot.
The techniques I used there are from here
Note that everything serializes well so that’s not an issue in this case (ScriptableObjects are used to get around the “Serializing polymorphic objects” issue)
Does anyone know what the proper usage should be here or if this a bug?
Regards,
Lorin