You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Unity中继承MonoBehaviour的抽象类JSON.NET反序列化报错求助

问题:继承MonoBehaviour的抽象类反序列化失败

报错详情

序列化继承自MonoBehaviour的抽象Measurement类时操作正常,但反序列化过程中抛出两个错误:

  1. 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 all
  2. ArgumentException: 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 11:24:52