unity
resource_error
ai_generated
true
UnityEditor.AssetDatabase:无法在路径 'Packages/com.example.custompackage/Resources/MyAsset.asset' 加载资源。未找到资源。
UnityEditor.AssetDatabase: Failed to load resource at path 'Packages/com.example.custompackage/Resources/MyAsset.asset'. Resource not found.
ID: unity/assetdatabase-package-resource-not-found
85%修复率
85%置信度
1证据数
2023-07-22首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| Unity 2022.3.8f1 | active | — | — | — |
| Unity 2023.1.1f1 | active | — | — | — |
根因分析
包内指定的路径不存在,通常是因为资源未放置在包内的“Resources”文件夹中,或者包未正确导入。
English
The specified path inside a package does not exist, often because the resource was not placed in a 'Resources' folder within the package, or the package is not properly imported.
官方文档
https://docs.unity3d.com/Manual/LoadingResourcesAtRuntime.html解决方案
-
确保资源位于包内的“Resources”文件夹中。例如,创建文件夹结构:`Packages/com.example.custompackage/Resources/MyAsset.asset`。然后使用 `AssetDatabase.LoadAssetAtPath<ScriptableObject>("Packages/com.example.custompackage/Resources/MyAsset.asset")`。 -
如果包是本地包,则使用相对项目根目录的路径,例如 `Assets/MyResources/MyAsset.asset`,而不是包路径。
-
验证包是否已正确安装并在项目窗口的“包”下可见。如果不可见,请通过包管理器重新安装包。
无效尝试
常见但无效的做法:
-
80% 失败
Moving the resource to a different folder within the package without using a 'Resources' folder will still fail because AssetDatabase.LoadResourceAtPath only searches 'Resources' folders.
-
90% 失败
Reimporting the package does not help if the resource path is incorrect or the folder structure is wrong.