【ML-Agents】ML-Agents示例项目导入unity报错解决
最近在跑ML-Agents的示例代码,无奈往unity中导入项目后,就出现报错。本文简要描述了各个报错的解决方法。
文章目录
- 一、error CS0234: The type or namespace name 'InputSystem' does not exist in the namespace 'UnityEngine' (are you missing an assembly reference?)
- 二、error CS0234: The type or namespace name 'Recorder' does not exist in the namespace 'UnityEditor' (are you missing an assembly reference?)
- 三、error CS0246: The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?)
一、error CS0234: The type or namespace name ‘InputSystem’ does not exist in the namespace ‘UnityEngine’ (are you missing an assembly reference?)
关于这个bug,github中有一个issue专门提到:https://github.com/Unity-Technologies/ml-agents/issues/5752
文中有人提到,可以通过删除 PushBlockWithInput 文件夹,或者通过安装指定版本 release-19 的 com.unity.ml-agents 和 com.unity.ml-agents.extensions 来解决。但似乎都不能从根本上解决问题。
有人提到:
I could fix the same Errors with the new Input Sytem: []https://docs.unity3d.com/Packages/com.unity.inputsystem@1.0/manual/Installation.html
此方法可行。打开上述链接,按照提示在unity中的package manager中安装 Input System 包即可。
二、error CS0234: The type or namespace name ‘Recorder’ does not exist in the namespace ‘UnityEditor’ (are you missing an assembly reference?)
UnityEditor.Recorder 是 Unity 的 录制工具 API,属于独立模块。报错的原因可能是未安装 Recorder 包。
解决方法:
- 打开 Package Manager (Window > Package Manager)
- 点击左上角 “+” > Add package by name…
- 输入包名:com.unity.recorder
- 安装 Recorder 包即可
三、error CS0246: The type or namespace name ‘Newtonsoft’ could not be found (are you missing a using directive or an assembly reference?)
Unity 项目中缺少 Newtonsoft.Json 库(也称为 Json.NET),安装一下就好。
解决方法:
- 打开 Unity Editor
- 菜单栏选择 Window > Package Manager
- 点击左上角的 “+” 按钮
- 选择 “Add package from git URL…”
- 输入:com.unity.nuget.newtonsoft-json
- 点击 Add