Game Data Editor using an EditorWindow

Hello guys! I am starting my unity development self-learning journey. Since I am a beginner I have many questions. I am using an EditorWindow to edit my game data, to load and save it.

if (gameData!=null)
        {
            SerializedObject serializedObject = new SerializedObject(this);
            SerializedProperty serializedProperty = serializedObject.FindProperty("gameData");

            EditorGUILayout.PropertyField(serializedProperty, true);

            serializedObject.ApplyModifiedProperties();

            if (GUILayout.Button("Save data"))
            {
                SaveGameData();
            }

            if (GUILayout.Button("Load data"))
            {
                LoadGameData();
            }

Unfortunately, I can’t understand why in my editor window I just can manage attributes of my classes.
For example, if I have a class Question with this:
public AnswerOptionText[] Answers ; → The answers appear in my editor window.

public AnswerOptionText[] Answers { get; set; } → The answers doesn’t appear in my editor window.

I need to use class properties, is there any way to use it and manage it on my editor window?
If someone can help me I would be very grateful. Thanks.

This happens because {get; set;} is an auto property, that translates to a get and a set method and a PRIVATE backing field, which are not shown in the inspector by default, you can see every private field by setting the Inspector to Debug Mode.
6198013--679972--upload_2020-8-12_21-29-24.png
6198013--679975--upload_2020-8-12_21-29-38.png

in C# 7.3, you can now specify an attribute targetting that backing field. So you can do this.

6198013--679981--upload_2020-8-12_21-33-11.png
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-7.3/auto-prop-field-attrs

1 Like

It is working now! Problem solved, thanks a lot!

1 Like