Unity中继承MonoBehaviour的抽象类JSON.NET反序列化报错求助
问题:继承MonoBehaviour的抽象类反序列化失败
报错详情
序列化继承自MonoBehaviour的抽象Measurement类时操作正常,但反序列化过程中抛出两个错误:
You are trying to create a MonoBehaviour using the 'new' keyword. This is not allowed. MonoBehaviours can only be added using AddComponent(). Alternatively, your script can inherit from ScriptableObject or no base class at allArgumentException: The value "null" is not of type "SerializableMeasurement" and cannot be used in this generic collection. Parameter name: value
项目背景
- 所有测量类型均派生自抽象
Measurement类,序列化时会转换为对应的SerializableMeasurement派生类 Measurement类作为树形数据结构中的节点存在,其他节点的序列化与反序列化功能均正常- 受项目架构限制,无法移除
Measurement类对MonoBehaviour的继承
相关代码文件
- 其他节点与序列化器实现:
ScriptDefs.cs - 派生测量类定义:
Measurement.cs、Measure_LineSeg.cs等
内容的提问来源于stack exchange,提问作者CocoaMilka
相关产品推荐
相关产品推荐

