Unity-Technologies/UnityCsReference · error · ArgumentNullException

Cannot add artifact dependency on empty GUID.

Error message

Cannot add artifact dependency on empty GUID.

What it means

AssetImportContext.DependsOnArtifact(GUID guid) registers a dependency on the import artifact (compiled/processed output) of the asset identified by guid. It throws ArgumentNullException with message 'Cannot add artifact dependency on empty GUID.' when guid.Empty() is true. This is the GUID overload, distinct from the ArtifactKey overload (error 28) and the string path overload (error 30).

Source

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

        public void DependsOnArtifact(ArtifactKey key)
        {
            if (!key.isValid)
            {
                throw new ArgumentNullException("key", "Cannot add dependency on invalid ArtifactKey.");
            }

            DependsOnArtifactInternal(key);
        }

        [NativeName("DependsOnArtifact")]
        private extern void DependsOnArtifactInternal(ArtifactKey key);

        public void DependsOnArtifact(GUID guid)
        {
            if (guid.Empty())
            {
                throw new ArgumentNullException("guid", "Cannot add artifact dependency on empty GUID.");
            }

            DependsOnArtifactInternalGUID(guid);
        }

        [NativeName("DependsOnArtifact")]
        private extern void DependsOnArtifactInternalGUID(GUID guid);

        public void DependsOnArtifact(string path)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("path", "Cannot add dependency on invalid path.");
            }

            DependsOnArtifactInternalPath(path);
        }

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Check guid.Empty() before calling: if (!guid.Empty()) context.DependsOnArtifact(guid).
  2. Validate GUIDs at parse time using GUID.TryParse and skip invalid references.
  3. Cache resolved GUIDs and validate them against AssetDatabase.GUIDToAssetPath before declaring dependencies.

Example fix

// before
context.DependsOnArtifact(depGuid);

// after
if (!depGuid.Empty())
    context.DependsOnArtifact(depGuid);
else
    Debug.LogWarning($"{context.assetPath}: empty GUID for artifact dependency, skipping");
Defensive patterns

Strategy: validation

Validate before calling

if (!guid.Empty())
    context.DependsOnArtifact(guid);
else
    Debug.LogWarning($"{context.assetPath}: empty GUID for artifact dependency");

Type guard

static bool IsValidGuid(GUID guid) => !guid.Empty();

Try / catch

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

Prevention

When it happens

Trigger: Calling context.DependsOnArtifact(guid) where guid is default/uninitialized (all zeros) or was set from a failed GUID.TryParse. Common when an importer reads artifact references from serialized data that includes optional or corrupted GUID fields.

Common situations: ScriptedImporters that depend on the processed output of other assets (e.g., a material depending on a compiled texture's artifact). The empty GUID arises from missing cross-references, migration issues, or assets that were deleted between serialization and import.

Related errors


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