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
- Check guid.Empty() before calling: if (!guid.Empty()) context.DependsOnArtifact(guid).
- Validate GUIDs at parse time using GUID.TryParse and skip invalid references.
- 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
- Check guid.Empty() before all GUID-based artifact dependency calls
- Validate GUIDs via GUID.TryParse and GUIDToAssetPath before registering
- Cache and validate resolved GUIDs to avoid stale references
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
- Cannot add source dependency on empty GUID.
- Cannot add dependency on invalid path.
- Cannot add custom dependency on an empty custom dependency.
- Cannot add dependency on invalid ArtifactKey.
- A shader '{assetPath}' cannot depend on the 'srp/default-sha
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/df64578b8c956f32.
Report an issue: GitHub.