The same field name is serialized multiple times in the class or its parent class. This is not supported: Base(WeaponBlockVars) <ObjType>k__BackingField
Unityのエラー「The same field name is serialized multiple times in the class or its parent class.」について - Qiita
この記事によると「継承元と継承先のクラスの同名Private変数をSerializeできないため」と書いてあったのですが、interfaceを継承した基底クラスのフィールドをoverrideした時にもなぜか発生するようです。
ただ、SerializeFieldとして出現するわけではないのに、このメッセージが出るのは気持ち悪いので、いろいろ検索してみました。
↓バグではないか?という記事
The same field name is serialized multiple times in the class or its parent class. This is not supported · Issue #1032 · accord-net/framework · GitHub
↑の記事によると一旦リネームして、もとに戻せば直るよということでしたが、直りませんでした。
環境
- Unity 2020.1.1f
再現手順
1. Addressablesのnew buildを行う
2. 再生ボタンを押す
とエラーが出力されます。
問題のコード(原因)
interfaceとMonoBehaviourを継承したBaseクラス。
そのBaseクラスを継承した派生クラス。
その派生クラスではBaseクラスのinterfaceメソッドをoverrideする。
public interface ISample { int Takoyaki { get; set;} } public class Base : MonoBehaviour, ISample { public virtual int Takoyaki { get; set;} = 1; } public class Derived: Base { public override int Takoyaki { get; set;} = 777; //←これがダメらしい・・・ }
解決策
不明。上記のコードで再現するけどいろいろゴニョゴニョやっている内に上記のコードはエラーが出なくなってしまった。
感想
モヤッとする・・・