Despite using [NonSerialized] on a member that deliberately hides another with the same name from the parent class, I get the occasional editor error message that unity is trying to serialize the same field twice. Specifically The same field name is serialized multiple times in the class or its parent class. This is not supported: Base(OnThingSelected) <assignedEffect >k__BackingField
Shouldn’t the field not be serialized, or even have a backing field to serialize, and why not throw the error for OnThingSelected
as it’s using the same behavior.
It’s likely I’m breaking a few polymorphism rules here, but without some major refactoring of the related systems I was hoping to just override the member.
Simplified example for clarity:
public class ThingLogics : MonoBehaviour {
public enum PhysicalEffect {
None,
Burn,
Freeze,
Acid
}
public enum VisualEffect {
None,
Sparkle,
Shine
}
//More stuff
}
public class ThingUI : MonoBehaviour {
[NonSerialized]//Assigned during generation by factory
public Action<ThingLogics.PhysicalEffect> OnThingSelected;
[NonSerialized]//Assigned during generation by factory
public ThingLogics.PhysicalEffect assignedEffect = ThingLogics.PhysicalEffect.None;
}
public class PrettyThingUI : ThingUI {
[NonSerialized]//Assigned during generation by factory
public new Action<ThingLogics.VisualEffect> OnThingSelected;
[NonSerialized]//Assigned during generation by factory
public new ThingLogics.VisualEffect assignedEffect = ThingLogics.VisualEffect.None;
}