- Home /
How can I check SerializedPropertyChangeEvent to see if changedProperty is valid?
As part of my custom PropertyDrawer
I have an enum
in a PropertyField
for which I've used RegisterValueChangeCallback()
to watch it for changes so I can re-draw fields in my VisualElement
when appropriate.
I have a MonoBehaviour
which holds a List of these Properties, and if I delete an entry from the encapsulating List, a SerializedPropertyChangeEvent
will get sent to the VisualElement
for the Property that is getting destroyed. As far as I can tell, there's no way to check for this from either the SerializedPropertyChangeEvent
or the PropertyField
, but as soon as I try to access a field on the changedProperty, I get an error in console saying:
SerializedProperty My.Long.Property.Path.data[i] has disappeared
Since it's an error I can't wrap anything in a try/catch, so I'm left wondering if there are any mechanisms at all to check that an event is valid before I hit the error?
Code looks roughly like this:
void OnModeChange(SerializedPropertyChangeEvent evt)
{
if (evt.currentTarget != m_ModeField ||
evt.changedProperty.propertyType != SerializedPropertyType.Enum ||
(AssetFilter.FilterMode)evt.changedProperty.enumValueIndex == m_LastModeRendered)
{
return;
}
ClearTransientFields();
DrawConditionalModeFields();
m_ModeProperty.serializedObject.ApplyModifiedProperties();
MarkDirtyRepaint();
}
As soon as I try to access any field in changedProperty
I will get the error, but I can't figure out what field, if any exists, I could check to ensure changedProperty
points at a valid object before I access it.
Your answer
![](https://koobas.hobune.stream/wayback/20220613053930im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Property Drawer inside Custom Editor? 1 Answer
How do I hide elements from a child class embedded in a List on the Inspector in the CustomEditor? 0 Answers
[noone knows] array of objects with CustomPropertyDrawer not displayed 0 Answers
Putting a UnityEvent PropertyDrawer into a Custom Editor Window 1 Answer
How to prevent EditorGUI.indent from overriding property height (only) 2 Answers