- Home /
Question by
Deadcow_ · Feb 22, 2016 at 05:57 PM ·
c#nullserializedpropertyserializedobject
Set SerializedProperty of custom type to null
I've got SerializedProperty of type List and I want to set this list to null, if arraySize == 0
I can't access property via objectReferenceValue, since List is not UnityObject type and I receive "type is not a supported pptr value" error.
This property placed in custom type, so I can't cast serializedObject reference to my type either.
Comment
Best Answer
Answer by Deadcow_ · Feb 23, 2016 at 02:43 PM
It was easy enough. I manage to cast to custom type with PropertyDrawer.fieldInfo.
Sound sound = fieldInfo.GetValue(property.serializedObject.targetObject) as Sound;
SerializedProperty clips = property.FindPropertyRelative("Clips");
if (sound != null && clips.arraySize == 0)
{
sound.Clips = null;
property.serializedObject.Update();
}
If I increase arraySize later, sound.Clips becomes not null. And while Clips is null arraySize is equals zero