Unity-Technologies/UnityCsReference · error · InvalidImportException
Cannot load. Path {path} is correct but AssetDatabase cannot
Error message
Cannot load. Path {path} is correct but AssetDatabase cannot load now. What it means
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.
Source
Thrown at Editor/Mono/RenderPipelineResourcesEditorUtils.cs:191
UnityEngine.Object Load(string path, Type type, SearchType location)
{
// Check if asset exist.
// Direct loading can be prevented by AssetDatabase being reloading.
var guid = AssetDatabase.AssetPathToGUID(path);
if (location == SearchType.ProjectPath && String.IsNullOrEmpty(guid))
throw new InvalidImportException($"Failed to find {path} in {location}.");
UnityEngine.Object result = type == typeof(Shader)
? LoadShader(path, location)
: LoadNonShaderAssets(path, type, location);
if (IsNull(result))
switch (location)
{
case SearchType.ProjectPath:
CheckTypeMismatch(path, type);
throw new InvalidImportException($"Cannot load. Path {path} is correct but AssetDatabase cannot load now.");
case SearchType.ShaderName: throw new InvalidImportException($"Failed to find {path} in {location}.");
case SearchType.BuiltinPath: throw new InvalidImportException($"Failed to find {path} in {location}.");
case SearchType.BuiltinExtraPath: throw new InvalidImportException($"Failed to find {path} in {location}.");
}
return result;
}
UnityEngine.Object LoadShader(string path, SearchType location)
{
switch (location)
{
case SearchType.ShaderName:
case SearchType.BuiltinPath:
case SearchType.BuiltinExtraPath:
return Shader.Find(path);
case SearchType.ProjectPath:
return AssetDatabase.LoadAssetAtPath(path, typeof(Shader));View on GitHub (pinned to 225b0fbdb5)
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.
Example fix
// before
// runs during [InitializeOnLoad] - AssetDatabase may not be ready
var shader = resource.Load(path, typeof(Shader), SearchType.ProjectPath);
// after
[InitializeOnLoad]
static class Loader
{
static Loader()
{
EditorApplication.delayCall += DoLoad;
}
static void DoLoad()
{
if (!EditorApplication.isCompiling && !EditorApplication.isUpdating)
var shader = resource.Load(path, typeof(Shader), SearchType.ProjectPath);
}
} Defensive patterns
Strategy: retry
Validate before calling
if (!EditorApplication.isCompiling && !EditorApplication.isUpdating)
var asset = resource.Load(path, type, SearchType.ProjectPath);
else
EditorApplication.delayCall += () => resource.Load(path, type, SearchType.ProjectPath); Try / catch
void TryLoadResource(Action<UnityEngine.Object> onSuccess, int maxRetries = 5)
{
try { onSuccess(resource.Load(path, type, SearchType.ProjectPath)); }
catch (InvalidImportException) when (EditorApplication.isCompiling || EditorApplication.isUpdating)
{
if (maxRetries > 0)
EditorApplication.delayCall += () => TryLoadResource(onSuccess, maxRetries - 1);
}
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Failed to find {path} in {location}.
- Host type is not matching any asset type at Path {path}.
- A shader '{assetPath}' cannot depend on the 'srp/default-sha
- ${renderPipelineType} must be a valid ${RenderPipeline}
- renderingLayerNames is null or empty
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/ad308a23e276210f.
Report an issue: GitHub.