Unity 报错之 The same field name is serialized multiple times in the class or its p

837 阅读1分钟

本文已参与掘金创作者训练营第三期「高产更文」赛道,详情查看:掘力计划|创作者训练营第三期正在进行,「写」出个人影响力。

Unity 报错之 The same field name is serialized multiple times in the class or its parent class.

Unity 报错之 同一字段名在类或其父级中序列化多次


报错图片: 报错

报错代码:

public class BaseClass : MonoBehaviour {

    public GameObject gameStart;
}

public class SubClass : BaseClass
{
    //不管是否是同一类型都会报这个错误.
    public GameObject gameStart;
    //public Transform gameStart;
}

在写子类代码时,VS会提示我们父类中有此成员,有意隐藏请使用关键字new,如下图: 111


解决方案:直接使用父类的定义,若不满足需求则可在子类中重新起名即可.

PS:我遇到这个问题时,怎么修改都不好用,最后重启了下Unity就好了,就很奇怪啊...