- Home /
Question by
laymelek · Oct 29, 2017 at 12:43 PM ·
c#editorserializefieldgetters
C#6 Serializefield is not working with getter and setter
Hello All,
I just enabled c#6 with 2017.3.b6. and define a simple property.
[SerializeField] public bool enableActionAfterAttack { get; internal set; } = false;
Getter and setter is working perfectly but the property is not available in editor. Do you know where can be the problem?
Comment
Best Answer
Answer by Bunny83 · Oct 29, 2017 at 01:46 PM
Because a property is not a field. Unity's serializer never supported serializing properties
here is a workaround http://wiki.unity3d.com/index.php/Expose_properties_in_inspector
But it works when I do this:
[SerializeField] bool enableActionAfterAttack
how come?
Perhaps the field it looks up is serialized? would need more code to confirm.
Because
[SerializeField] bool enableActionAfterAttack;
is a field, while
[SerializeField] public bool enableActionAfterAttack { get; internal set; } = false;
is a property.
Unity can't serialize properties.
Your answer
![](https://koobas.hobune.stream/wayback/20220612142103im_/https://answers.unity.com/themes/thub/images/avi.jpg)