- Home /
The same field name is serialized multiple times in the class or its parent class. This is not supported:
Can someone please explain why I am getting this error even though it is an override? Is this a bug in unity or am I doing something wrong? Error:
The same field name is serialized multiple times in the class or its parent class. This is not supported: Base(ShieldCustomInspector) <LastEditor>k__BackingField
Relevant Code:
[CustomEditor(typeof(Item),true)]//customizes the item class in the inspector
public class ItemCustomInspector : Editor
{
public virtual string LastEditor { get; set; } = "item";
public override void OnInspectorGUI()
{
if(LastEditor == "item")
{
//draw crap that I want to have at the very end of my inspector only once
}
}
}
[CustomEditor(typeof(HeldItem),true)]//customizes the item class in the inspector
public class HeldItemCustomInspector : ItemCustomInspector
{
public override string LastEditor { get; set; } = "heldItem";
public override void OnInspectorGUI()
{
if (LastEditor == "heldItem")
{
//draw crap that I want to have at the very end of my inspector only once
}
}
}
[CustomEditor(typeof(Shield), true)]//customizes the item class in the inspector
public class ShieldCustomInspector : HeldItemCustomInspector
{
public override string LastEditor { get; set; } = "shield";
public override void OnInspectorGUI()
{
if (LastEditor == "shield")
{
//draw crap that I want to have at the very end of my inspector only once
}
}
}
Answer by sacredgeometry · Dec 01, 2020 at 04:03 AM
Inheritance is not the best pattern if what you want is polymorphism.
Removing the CustomEditorAttribute
from the ItemCustomInspector would be the quickest fix but refactoring it to a better pattern would be the better one.
But to answer your question. No it doesn't look like a bug it looks like a misuse of a reasonably sensible implementation.
Your answer
![](https://koobas.hobune.stream/wayback/20220613020851im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Using the object.Equals() method for a custom class 1 Answer
Why is Start() from my base class ignored in my sub-class? 4 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Generic CustomEditor 1 Answer