Custom Editor problem with FindingProperty
Hello, I was trying to create CustomEditor for my custom list but I got null reference exception when I am trying to show it. Anyway I know why it's happening but don't know is there a way to fix it.
for(int i = 0; i < thisList.arraySize; i++)
{
SerializedProperty reference = thisList.GetArrayElementAtIndex(i);
SerializedProperty spellID = reference.FindPropertyRelative("spellID");
EditorGUILayout.PropertyField(spellID);
}
So I got this loop, it's not full yet but for the test I just put one field from my custom data. I know it would have worked if I had this kind of variable: public SpellsID spellID;
But I've got something like this without any "real" fields:
public SpellsID spellID { get; }
What you have a is a property and Unity does not serialize properties. There is no way to "fix" it.
Sad to hear that cause it's only getter/setter, it doesn't do nothing fancy and it gives you the same result as variable/field. I got it working but I had to add private fields with [SerializeField] and get it sync with getters/setters. Thank you anyway.
Unity cannot assume the property does the same as a field. Shorthand getter/setter syntax is just C# syntax sugar and the serializer sees the full get/set methods ins$$anonymous$$d. It cannot assume those methods don't have unintended consequences elsewhere.
Your answer
![](https://koobas.hobune.stream/wayback/20220612034706im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Crash when reimporting custom assets 0 Answers
Custom UnityEngine.UI button inspector 1 Answer
Adding custom edits to scene window 0 Answers