问题阐述
在Unity(版本号:2021.3.5f1c1)对使用Universal Render Pipeline(URP)渲染管线的Universal 3D模板进行项目创建的时候可能会报错: An error occurred while resolving packages: Project has invalid dependencies: com.unity.render-pipelines.universal: Package [com.unity.render-pipelines.universal@12.1.3] cannot be found.具体形式如下
问题解决
(1)首先,找到创建项目时候采用的项目模板,分为两种:一种是安装好编辑器时自带的 2D(Built-In Render Pipeline)和3D(Built-In Render Pipeline);一种是在图1-1界面选择下载的各种模板。(PS:想要了解更多关于Unity项目模板知识的可以看看这一篇:深入了解Unity项目模板)
①第一种模板的位置位于(仅作为示例,具体需要看自己电脑上Unity的编辑器安装位置)
C:\Program Files\Unity\Hub\Editor\2022.3.17f1c1\Editor\Data\Resources\PackageManager\ProjectTemplates
②第二种模板的位置位于
C:\Users<user>\AppData\Roaming\UnityHub\Templates
因为这里出错时采用的模板是使用Universal Render Pipeline(URP)渲染管线的Universal 3D模板,因为通过第②种方式查找模板位置如下
(2)通过文件夹中的manifest.json
打开可以查询上述模板中,哪个是我们使用的模板,例如这里打开之后显示
{“2021.3.5f1c1”:{“dependencies”:{“com.unity.template.urp-blank”:“2.0.6”,“com.unity.template.3d”:“4.2.8”}},“2023.2.20f1c1”:{“dependencies”:{“com.unity.template.urp-blank”:“16.0.0”}}}
这里可以看到,使用的2021.3.5f1c1版本编辑器的模板名称为com.unity.template.urp-blank-2.0.6
。因此,返回文件夹,并以压缩包的形式打开com.unity.template.urp-blank-2.0.6
。打开之后的内容如下。
(3)在打开的页面继续往下
\ProjectData~\Packages
至如下文件夹
,并打开manifest.json
。发现了与报错内容高度相似的"com.unity.render-pipelines.universal": "12.1.3"
。好了至此,我们需要开始准备修改了。
(4)首先,我们需要确认该版本的URP渲染管线插件适用的版本,经过尝试发现,12.1.7
版本符合要求,因此,我们需要将manifest.json
中的"com.unity.render-pipelines.universal": "12.1.3"
修改为"com.unity.render-pipelines.universal": "12.1.7"
。但是.tgz
文件是无法直接修改的。
这里我们将com.unity.template.urp-blank-2.0.6
的后缀改为压缩包格式如.zip
并解压缩成可修改的文件。将manifest.json
中的"com.unity.render-pipelines.universal": "12.1.3"
修改为"com.unity.render-pipelines.universal": "12.1.7"
后,重新压缩成.zip
格式,再将后缀改为.tgz
。并替代原来的com.unity.template.urp-blank-2.0.6
(这里注意,最好在解决报错前,将原版本留存一份)。
重新创建可以发现,不会报错了