Unity-Technologies/UnityCsReference · error · Exception

A shader '{assetPath}' cannot depend on the 'srp/default-sha

Error message

A shader '{assetPath}' cannot depend on the 'srp/default-shader' custom dependency because this operation is unsupported.

What it means

AssetImportContext.DependsOnCustomDependency throws a plain Exception (not ArgumentNullException) with an interpolated message when a shader asset (.shader file) attempts to depend on the reserved custom dependency 'srp/default-shader'. This restriction exists because the SRP default shader dependency is a system-level key that shaders themselves must not depend on — it would create a circular or unsupported dependency in the shader import pipeline. The check uses string.CompareOrdinal for exact matching and assetPath.EndsWith('.shader').

Source

Thrown at Editor/Mono/AssetPipeline/AssetImportContext.bindings.cs:229

            if (!AssetDatabase.TryGetGUIDAndLocalFileIdentifier(artifact.entityId, out string guidString, out long _)
                || !GUID.TryParse(guidString, out GUID guid))
            {
                return;
            }

            DependsOnArtifact(guid);
        }

        public void DependsOnCustomDependency(string dependency)
        {
            if (string.IsNullOrEmpty(dependency))
            {
                throw new ArgumentNullException("dependency", "Cannot add custom dependency on an empty custom dependency.");
            }

            if (string.CompareOrdinal(dependency,"srp/default-shader") == 0 && assetPath.EndsWith(".shader", StringComparison.OrdinalIgnoreCase))
            {
                throw new Exception($"A shader '{assetPath}' cannot depend on the 'srp/default-shader' custom dependency because this operation is unsupported.");
            }

            DependsOnCustomDependencyInternal(dependency);
        }

        [NativeName("DependsOnCustomDependency")]
        private extern void DependsOnCustomDependencyInternal(string path);

        extern void AddImportLog(string msg, string file, int line, ImportLogFlags flags, UnityEngine.Object obj);

        void AddImportLog(string msg, ImportLogFlags flags, UnityEngine.Object obj)
        {
            var st = new StackTrace(2, true);
            var sf = st.GetFrame(0);
            AddImportLog(msg, sf.GetFileName(), sf.GetFileLineNumber(), flags, obj);
        }

        public void LogImportError(string msg, UnityEngine.Object obj = null)

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Exclude shader assets from the 'srp/default-shader' dependency: check if assetPath ends with '.shader' before registering that specific dependency.
  2. Use a different, non-reserved custom dependency name for shader-related cache invalidation.
  3. Separate the dependency-registration logic by asset type so shaders never receive the reserved key.

Example fix

// before
context.DependsOnCustomDependency("srp/default-shader");

// after
bool isShader = context.assetPath.EndsWith(".shader", StringComparison.OrdinalIgnoreCase);
if (!isShader)
    context.DependsOnCustomDependency("srp/default-shader");
Defensive patterns

Strategy: validation

Validate before calling

bool isShader = context.assetPath.EndsWith(".shader", StringComparison.OrdinalIgnoreCase);
if (!(isShader && dependency == "srp/default-shader"))
    context.DependsOnCustomDependency(dependency);

Type guard

static bool IsSafeCustomDependency(string assetPath, string dep)
    => !(dep == "srp/default-shader" && assetPath.EndsWith(".shader", StringComparison.OrdinalIgnoreCase));

Try / catch

try { context.DependsOnCustomDependency(dependency); }
catch (Exception ex) when (ex.Message.Contains("srp/default-shader"))
{ Debug.LogWarning($"Skipped reserved custom dependency for shader: {context.assetPath}"); }

Prevention

When it happens

Trigger: Calling context.DependsOnCustomDependency("srp/default-shader") from a ScriptedImporter whose assetPath ends with '.shader'. This can happen if a custom dependency name is dynamically built or if a generic importer incorrectly applies SRP-related dependencies to shader assets.

Common situations: Custom ScriptedImporters or post-processors that blanket-apply SRP dependencies to all assets including shaders. Also occurs after Unity version upgrades where the SRP default-shader dependency name was introduced as a reserved key, and older importer code was not updated to exclude shaders.

Related errors


AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13). Data as JSON: /api/errors/f22da2d0169b1a06. Report an issue: GitHub.