- Home /
Field in PropertyDrawer isn't remembered
The selection index resets to 0 every time I highlight something else on the inspector
[CustomPropertyDrawer(typeof(FreyrDelegateBase), true)]
public class FreyrDelegateEditor : PropertyDrawer
{
int selected;
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
selected = EditorGUI.Popup(position, selected, new string[] { "one", "two", "three" });
}
}
Answer by Bunny83 · Oct 25, 2020 at 01:03 PM
Well, of course it would not be remembered since a property drawer is just responsible for drawing / displaying the serialized data of the serialized property it is invoked for. PropertyDrawers are not persistent objects, so you can not store anything in them that should persist. Currently your drawer doesn't read nor write any of the serialized data of the property. So it's not really clear what this is supposed to do and what kind of serialized field you have attached this drawer to.
Keep in mind that a property drawer can not change what is actually serialized and what is not serialized. PropertyDrawers are there for the visual representation of the serialized data. So if you want to show a popup with some predefined values, you have to actually change the serialized data of the property. Also in order to reconstruct the index you have to find a way to determine the index from the actual serialized data.
Your answer
Follow this Question
Related Questions
Set the Rect of PopupWindowContent 1 Answer
How To Draw a PropertyDrawer within a PropertyDrawer 0 Answers
Property Drawers not working with classes generated using TypeBuilder 0 Answers
How to show type text in EditorGUI.ObjectField? 1 Answer
Restricting enum options in inspector when using a propertydrawer. 0 Answers