I have a field of a GameObject that is a concretized subclass of UnityEvent.
I am trying to write a property drawer for that concretized subclass.
But UnityEventBase does not seem to be a child class of Object so using property.objectReferenceValue does not return anything that I can cast to my sub-class.
How does one get the deserailized property where such a property is a subclass of UnityEvent?
Here’s a workaround that lets you access the proper UnityEvent object instead of just the serialized data
public UnityEvent GetUnityEvent(object obj, string fieldName){
if( obj != null ) {
FieldInfo fi = obj.GetType().GetField(fieldName);
if( fi != null ) {
return fi.GetValue(obj) as UnityEvent;
}
}
return null;
}
The answer from Unity support is thus:
UnityEvent is a “normal” class, you
should be able to use
SerializedProperty.Next() to drill
down into its data but not
objectReferenceValue.
SO, I guess we have to use the SerializedProperty sub-property parsing function to get at the data.