- Home /
Marking property as dirty in property drawer after changing its objectReferenceValue
I've got an attribute that restricts a serialized field to be of a certain type. It works well, except for one problem. When I use this attribute on a prefab's serialized field and change it from outside the prefab editor, the property never gets dirtied.
property.objectReferenceValue =
EditorGUI.ObjectField(position, label, property.objectReferenceValue, type);
I can't use EditorGUI.PropertyField(position, property, label);
, since there's nothing I can use to enforce the type of the property.
I want a way to dirty the property when it changes object its objectReferenceValue
Answer by JeffBert · Jun 11, 2020 at 11:57 PM
I needed to wrap my assignment with BeginProperty
and EndProperty
calls
EditorGUI.BeginProperty(position, GUIContent.none, property);
property.objectReferenceValue =
EditorGUI.ObjectField(position, label, property.objectReferenceValue, type);
EditorGUI.EndProperty();
Your answer
Follow this Question
Related Questions
Show transparent version of prefab before instantiation 1 Answer
How to prevent prefab of custom editor inspector from overriding array size. 1 Answer
Automatically increment an integer field in a bunch of prefab gameobjects in the unity editor. 0 Answers
Unity setting SerializedProperty.prefabOverride incorrectly 2 Answers
Serialization with custom editor, prefab not saving (again) 1 Answer