unity resource_error ai_generated true

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

Also available as: JSON · Markdown · 中文
85%Fix Rate
85%Confidence
1Evidence
2023-07-22First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
Unity 2022.3.8f1 active
Unity 2023.1.1f1 active

Root Cause

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.

generic

中文

包内指定的路径不存在,通常是因为资源未放置在包内的“Resources”文件夹中,或者包未正确导入。

Official Documentation

https://docs.unity3d.com/Manual/LoadingResourcesAtRuntime.html

Workarounds

  1. 90% success Ensure the resource is inside a 'Resources' folder within the package. For example, create the folder structure: `Packages/com.example.custompackage/Resources/MyAsset.asset`. Then use `AssetDatabase.LoadAssetAtPath<ScriptableObject>("Packages/com.example.custompackage/Resources/MyAsset.asset")`.
    Ensure the resource is inside a 'Resources' folder within the package. For example, create the folder structure: `Packages/com.example.custompackage/Resources/MyAsset.asset`. Then use `AssetDatabase.LoadAssetAtPath<ScriptableObject>("Packages/com.example.custompackage/Resources/MyAsset.asset")`.
  2. 85% success If the package is local, use `AssetDatabase.LoadAssetAtPath` with a relative path from the project root, e.g., `Assets/MyResources/MyAsset.asset`, instead of a package path.
    If the package is local, use `AssetDatabase.LoadAssetAtPath` with a relative path from the project root, e.g., `Assets/MyResources/MyAsset.asset`, instead of a package path.
  3. 75% success Verify the package is properly installed and visible in the Project window under Packages. If not, reinstall the package via the Package Manager.
    Verify the package is properly installed and visible in the Project window under Packages. If not, reinstall the package via the Package Manager.

中文步骤

  1. 确保资源位于包内的“Resources”文件夹中。例如,创建文件夹结构:`Packages/com.example.custompackage/Resources/MyAsset.asset`。然后使用 `AssetDatabase.LoadAssetAtPath<ScriptableObject>("Packages/com.example.custompackage/Resources/MyAsset.asset")`。
  2. 如果包是本地包,则使用相对项目根目录的路径,例如 `Assets/MyResources/MyAsset.asset`,而不是包路径。
  3. 验证包是否已正确安装并在项目窗口的“包”下可见。如果不可见,请通过包管理器重新安装包。

Dead Ends

Common approaches that don't work:

  1. 80% fail

    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.

  2. 90% fail

    Reimporting the package does not help if the resource path is incorrect or the folder structure is wrong.