コガネブログ

平日更新を目標にUnityやC#などのゲーム開発アレコレを書いていきます

【Unity】The same field name is serialized multiple times in the class or its parent class. This is not supported: -> AAAA(MonoBehaviour) BBBB(CCCC) DDDD

The same field name is serialized multiple times in the class or its parent class. 
This is not supported:  -> AAAA(MonoBehaviour) BBBB(CCCC) DDDD

基底クラスと派生クラスで同名のフィールドをシリアライズ可能にした場合
上記のエラーが発生します

using System;
using UnityEngine;

[Serializable]
public class Character
{
    [SerializeField] private int mId;
}

[Serializable]
public class Player : Character
{
    [SerializeField] private int mId;
}

public class ExampleClass: MonoBehaviour
{
    [SerializeField] private Player mPlayer;
}