Unity-Technologies/UnityCsReference · error · ArgumentNullException

Cannot add custom dependency on an empty custom dependency.

Error message

Cannot add custom dependency on an empty custom dependency.

What it means

AssetImportContext.DependsOnCustomDependency(string dependency) registers a named custom dependency that, when changed, triggers re-import. It throws ArgumentNullException with message 'Cannot add custom dependency on an empty custom dependency.' when dependency is null or empty. Custom dependencies are user-defined hash-keyed entries registered via AssetDatabase.RegisterCustomDependency, used for coarse-grained cache invalidation.

Source

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

        public void DependsOnArtifact<T>(LazyLoadReference<T> artifact) where T : Object
        {
            if (!artifact.isSet)
                return;

            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);

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Validate the dependency name: if (!string.IsNullOrEmpty(dep)) context.DependsOnCustomDependency(dep).
  2. Ensure custom dependency names are defined as constants and always non-empty.
  3. Register the custom dependency via AssetDatabase.RegisterCustomDependency before referencing it in DependsOnCustomDependency.

Example fix

// before
context.DependsOnCustomDependency(settingsKey);

// after
if (!string.IsNullOrEmpty(settingsKey))
    context.DependsOnCustomDependency(settingsKey);
else
    Debug.LogWarning($"{context.assetPath}: empty custom dependency name, skipping");
Defensive patterns

Strategy: validation

Validate before calling

if (!string.IsNullOrEmpty(dependency))
    context.DependsOnCustomDependency(dependency);
else
    Debug.LogWarning($"{context.assetPath}: empty custom dependency name");

Type guard

static bool IsValidCustomDependency(string dep) => !string.IsNullOrEmpty(dep);

Try / catch

try { context.DependsOnCustomDependency(dependency); }
catch (ArgumentNullException ex) when (ex.ParamName == "dependency")
{ Debug.LogWarning($"Skipped custom dependency: {ex.Message}"); }

Prevention

When it happens

Trigger: Calling context.DependsOnCustomDependency(null) or context.DependsOnCustomDependency("") from a ScriptedImporter's OnImportAsset. The dependency name typically comes from configuration, serialized settings, or computed strings that can be empty if unconfigured.

Common situations: Importers that depend on global settings (e.g., color space, build target, shader compilation flags) registered as custom dependencies. The empty string arises from unconfigured settings, conditional logic that skips name assignment, or version changes where a custom dependency key was renamed or removed.

Related errors


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