{"record":{"id":"ad308a23e276210f","repo":"Unity-Technologies/UnityCsReference","slug":"cannot-load-path-path-is-correct-but-assetdatab","errorCode":null,"errorMessage":"Cannot load. Path {path} is correct but AssetDatabase cannot load now.","messagePattern":"Cannot load\\. Path (.+?) is correct but AssetDatabase cannot load now\\.","errorType":"exception","errorClass":"InvalidImportException","httpStatus":null,"severity":"error","filePath":"Editor/Mono/RenderPipelineResourcesEditorUtils.cs","lineNumber":191,"sourceCode":"\n            UnityEngine.Object Load(string path, Type type, SearchType location)\n            {\n                // Check if asset exist.\n                // Direct loading can be prevented by AssetDatabase being reloading.\n                var guid = AssetDatabase.AssetPathToGUID(path);\n                if (location == SearchType.ProjectPath && String.IsNullOrEmpty(guid))\n                    throw new InvalidImportException($\"Failed to find {path} in {location}.\");\n\n                UnityEngine.Object result = type == typeof(Shader)\n                    ? LoadShader(path, location)\n                    : LoadNonShaderAssets(path, type, location);\n                \n                if (IsNull(result))\n                    switch (location)\n                    {\n                        case SearchType.ProjectPath:\n                            CheckTypeMismatch(path, type);\n                            throw new InvalidImportException($\"Cannot load. Path {path} is correct but AssetDatabase cannot load now.\");\n                        case SearchType.ShaderName: throw new InvalidImportException($\"Failed to find {path} in {location}.\");\n                        case SearchType.BuiltinPath: throw new InvalidImportException($\"Failed to find {path} in {location}.\");\n                        case SearchType.BuiltinExtraPath: throw new InvalidImportException($\"Failed to find {path} in {location}.\");\n                    }\n                    \n                return result;\n            }\n\n            UnityEngine.Object LoadShader(string path, SearchType location)\n            {\n                switch (location)\n                {\n                    case SearchType.ShaderName:\n                    case SearchType.BuiltinPath:\n                    case SearchType.BuiltinExtraPath:\n                        return Shader.Find(path);\n                    case SearchType.ProjectPath:\n                        return AssetDatabase.LoadAssetAtPath(path, typeof(Shader));","sourceCodeStart":173,"sourceCodeEnd":209,"githubUrl":"https://github.com/Unity-Technologies/UnityCsReference/blob/225b0fbdb57cc17d094e8056b71f8314aba56f73/Editor/Mono/RenderPipelineResourcesEditorUtils.cs#L173-L209","documentation":"RenderPipelineResourcesEditorUtils.Load throws InvalidImportException when a ProjectPath asset has a valid GUID but AssetDatabase cannot currently load it. This happens during AssetDatabase reload/import phases when direct asset loading is temporarily blocked.","triggerScenarios":"Loading a render pipeline resource at a ProjectPath where the GUID exists (asset is present) but AssetDatabase.LoadAssetAtPath returns null because the AssetDatabase is mid-reload or mid-import.","commonSituations":"Code runs during AssetDatabase.Refresh or domain reload, when the AssetDatabase is temporarily unavailable. Common in editor initialization, [InitializeOnLoad] methods, or AssetPostprocessor callbacks that trigger render pipeline resource access too early.","solutions":["Defer the load until AssetDatabase is ready: use EditorApplication.delayCall or a deferred initialization flag.","Check EditorApplication.isCompiling and EditorApplication.isUpdating and retry after they complete.","Use AssetDatabase.LoadAssetAtPath in a context where the database is settled (e.g., not during import callbacks).","Subscribe to AssetDatabase.importPackageCompleted or EditorApplication.update to retry the load once.","Wrap in try-catch for InvalidImportException and retry on next editor update tick."],"exampleFix":"// before\n// runs during [InitializeOnLoad] - AssetDatabase may not be ready\nvar shader = resource.Load(path, typeof(Shader), SearchType.ProjectPath);\n// after\n[InitializeOnLoad]\nstatic class Loader\n{\n    static Loader()\n    {\n        EditorApplication.delayCall += DoLoad;\n    }\n    static void DoLoad()\n    {\n        if (!EditorApplication.isCompiling && !EditorApplication.isUpdating)\n            var shader = resource.Load(path, typeof(Shader), SearchType.ProjectPath);\n    }\n}","handlingStrategy":"retry","validationCode":"if (!EditorApplication.isCompiling && !EditorApplication.isUpdating)\n    var asset = resource.Load(path, type, SearchType.ProjectPath);\nelse\n    EditorApplication.delayCall += () => resource.Load(path, type, SearchType.ProjectPath);","typeGuard":null,"tryCatchPattern":"void TryLoadResource(Action<UnityEngine.Object> onSuccess, int maxRetries = 5)\n{\n    try { onSuccess(resource.Load(path, type, SearchType.ProjectPath)); }\n    catch (InvalidImportException) when (EditorApplication.isCompiling || EditorApplication.isUpdating)\n    {\n        if (maxRetries > 0)\n            EditorApplication.delayCall += () => TryLoadResource(onSuccess, maxRetries - 1);\n    }\n}","preventionTips":["Defer render pipeline resource loading until after compilation/import completes","Avoid loading assets in [InitializeOnLoad] static constructors; use delayCall","Check EditorApplication.isCompiling and isUpdating before AssetDatabase operations","Use AssetDatabase.importPackageCompleted or EditorApplication.update to retry deferred loads"],"tags":["unity","render-pipeline","srp","assetdatabase-reload","timing"],"backgroundTag":null,"analyzedSha":"225b0fbdb57cc17d094e8056b71f8314aba56f73","analyzedAt":"2026-08-13T19:07:19.849Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}