Version: 2019.2
覆盖 Unity 的冲突解决方式
网络问题

故障排除

本节提供有关以下问题的信息:

Package Manager 窗口中的错误消息

在 Package Manager 遇到问题时,Package Manager 窗口中会显示错误指示符:

  • 系统范围的问题

Error messages that appear in the status bar indicate the Package Manager has detected an issue that is not related to a specific package. For example, if the Package Manager cannot access the package registry server, it displays this message in the status bar:

网络错误消息

如果您的网络无法访问包注册表服务器,可能是因为网络存在连接问题。您或系统管理员修复网络错误后,状态栏将清空。

  • 包特有的问题

If a specific package has a problem when loading or installing, the error icon (error indicator) appears in the package list next to the compromised package. To find out what the problem is, open the compromised package’s details view.

Package Manager 缺失或者窗口无法打开

如果您的 package.manifest 文件有格式错误,则在 Unity 控制台中将出现类似以下错误:

Failed to resolve packages: The file [<project-path>/Packages/manifest.json] is not valid JSON:
  Unexpected token '}' at 44:1
  }

您可以使用错误消息中包含的信息来修复 JSON。您可以使用许多在线验证器来更正问题。保存更正的文件后,Unity 将重新加载 Package Manager 窗口。

If your package.manifest file is missing the reference to the com.unity.package-manager-ui package, you might not see any error messages in the console, and your packages might appear in the Project view, but you can’t open the Package Manager window because the Package Manager menu item does not appear in the Window menu. You can either reset your Project’s package configuration or add the following to the dependencies list:

    "com.unity.package-manager-ui": "2.1.1",

如果 Package Manager 窗口仍然缺失,请重新启动 Unity。

If you are still experiencing problems, check to see if your Project manifest uses “exclude” as a package version. This is an obsolete value for the dependencies attribute. If you find any lines like these, remove the entire line. Package Manager only installs packages that are explicitly included as a dependency in your Project, so once you remove that entry, Package Manager ignores the package and doesn’t install it.

If the Package Manager still fails to load, follow the procedures under Packages not recognized and Resetting your Project’s package configuration.

将 Unity 升级到新版本后出现的问题

When you upgrade a Project to a newer Unity version, the Package Manager automatically updates incompatible packages to newer compatible versions. However, if your package doesn’t compile, the Package Manager displays error messages in the Console.

要处理这些消息,请阅读错误消息并尽可能解决所有问题。例如,一个包可能缺少对另一个包或版本的依赖。在这种情况下,您可以尝试自己安装该包。

您也可以按照以下顺序来尝试每个解决方案,直到找到可行的解决方案:

  • Back up and then delete the Packages folder under your Project.
  • Back up and then delete the package sources in your Project’s Packages folder, leaving only the manifest.json file. Then try to reload the Project.
  • Create a new empty Project. If the Package Manager window loads successfully, replace the Library/PackageCache/com.unity.package-manager-ui@<version> folder in the failing Project with the same folder from the newly created Project.
  • As a last resort, you can reset your Project to the default package configuration and add back packages one at a time until it works.

包安装失败

如果您尝试从注册表安装新的包但无法安装,可能是由于权限问题所致。

必须对缓存文件夹具有完整权限:

  • Windows:C:\Users\yourname\AppData\Local\Unity\cache
  • MacOS:~/Users/Library/Unity/cache

可能是网络存在问题。检查您的防火墙代理设置。

有时,学校、政府机关或受网络保护的工作场所等机构环境会设置代理服务器来控制网络与互联网之间的通信,并使用自己的服务器证书,而 Unity 或 Package Manager 无法识别这些证书。请与您的网络管理员联系。

无法识别包

If you see a lot of compilation errors, this might indicate that Unity is not recognizing the packages in your existing Project. In this case, you might be missing a .NET component.

对于 Windows:

1.下载并安装 Visual Studio 2017 版本 15.9.0 或更高版本,并在 Other Toolsets 下面选中 .NET Core cross-platform development workload。 2.下载并安装 .NET SDK v2.2.101 组件。

对于 MacOS:

1.下载并安装 .NET SDK v2.2.101 组件。

2.在 Visual Studio 中安装所有建议的更新

3.使用 homebrew 来计划和安装 mono

```shell
  brew update
    brew install mono # optional
    brew upgrade mono
```
  1. If necessary, delete the Library/obj/temp folder under your Project and restart Unity.

5.如果仍然遇到困难,请尝试重新启动计算机。

Windows 上加载 hostfxr.dll 时出错

如果控制台报告说找到了 hostfxr.dll 库,但 Unity 无法从 C:\<path_to_app>\hostfxr.dll 加载该库,那么可以通过安装 KB2999226KB2533623 补丁在 Windows 7 或 Windows Server 2008 R2 上修正此错误。

Resetting your Project’s package configuration

If a Project has too many package issues, you can reset your Project back to the default package configuration for the Editor’s version of Unity. This operation resets all packages in your Project. This might not fix the source of the problem, but it can help you figure out what the problem is.

NOTE: You can’t undo resetting your package configuration, so make sure you back up the manifest.json file first or make sure your Project is under source control. You can also take extra precautions by cloning your Project and testing out the operation on the clone before proceeding.

To return to the default package configuration, select Reset Packages to defaults from the Help menu.

Help > Reset Packages to defaults
Help > Reset Packages to defaults

Resetting a clone of your Project

在执行最终更改之前,您也可以测试是否可以恢复为默认包:

  1. Clone your Project by copy-pasting your Project folder and renaming it so that it is easy to find (for example, if your Project is called MyProject then you could use something like clone_MyProject).

  2. Load your newly cloned Project.

3.从 Help 菜单中,选择 Reset Packages to defaults

Depending on the size of your Project, this might take a few minutes.
  1. Check that it successfully reset the packages. If so, you can perform the operation safely on the original Project.

Git URL 的身份验证问题

如果使用 SSH 协议通过 Git URL 来安装包,即使您正在后台运行 ssh-agent 并且您的 PID 环境变量已正确设置,也可能会遇到来自 Git 的身份验证错误。

尽管您的脚本可以在后台成功启动 ssh-agent,但是导出的环境变量仅适用于运行脚本的 Bash shell 以及之后由该脚本启动的任何子进程。这是因为您的脚本无法更改父进程、无关进程或先前创建的子进程中的环境变量。即使脚本位于 .bashrc 中,也只会在 Bash shell 中执行。

通过双击 Unity 图标或使用 Hub 启动 Unity 或 Unity Hub(在 Windows 和 macOS 中)时,不会在 shell 中运行,因此不会执行脚本。这意味着 Unity Editor 进程不会设置这些变量,因此 Unity 调用的 Git 进程最终也不会设置这些变量。

要解决此问题,可以执行以下操作之一:

  • 首先打开 Bash shell(在打开 Hub 之前),然后从该 shell 中手动启动 Unity Editor
  • 如果您使用的是 Windows,则可以使用 setx 命令在 Hub 进程启动之前在 Windows 注册表中永久设置环境变量。如果您可以确保脚本在启动时运行一次,并且 Hub 不会与 Windows 一起启动,则此解决方案最有效。例如:
  # Expose env variables to native windows
    setx SSH_AGENT_PID "$SSH_AGENT_PID"
    setx SSH_AUTH_SOCK "$SSH_AUTH_SOCK"
覆盖 Unity 的冲突解决方式
网络问题