Unity-Technologies/UnityCsReference · error · ArgumentNullException
name
Error message
name
What it means
AssetImporter.SourceAssetIdentifier(Type type, string name) constructor throws ArgumentNullException with param name 'name' when name is null. This is a distinct check from the empty-string check (error 36): null triggers ArgumentNullException, empty string triggers ArgumentException. The name field stores the sub-asset's name for import remapping.
Source
Thrown at Editor/Mono/AssetPipeline/AssetImporter.bindings.cs:47
if (asset == null)
{
throw new ArgumentNullException("asset");
}
this.type = asset.GetType();
this.name = asset.name;
}
public SourceAssetIdentifier(Type type, string name)
{
if (type == null)
{
throw new ArgumentNullException("type");
}
if (name == null)
{
throw new ArgumentNullException("name");
}
if (string.IsNullOrEmpty(name))
{
throw new ArgumentException("The name is empty", "name");
}
this.type = type;
this.name = name;
}
public Type type;
public string name;
}
[NativeName("AssetPathName")]
public extern string assetPath
{View on GitHub (pinned to 225b0fbdb5)
Solutions
- Null-check name: if (name != null) new SourceAssetIdentifier(type, name).
- Coalesce null to empty string only if empty is acceptable: name = name ?? string.Empty (but note error 36 will fire if empty).
- Validate serialized data has non-null, non-empty name fields before constructing identifiers.
Example fix
// before
var id = new SourceAssetIdentifier(type, subAssetName);
// after
if (!string.IsNullOrEmpty(subAssetName))
var id = new SourceAssetIdentifier(type, subAssetName);
else
Debug.LogWarning($"Skipping SourceAssetIdentifier: name is null or empty for type {type}"); Defensive patterns
Strategy: validation
Validate before calling
if (!string.IsNullOrEmpty(name))
var id = new AssetImporter.SourceAssetIdentifier(type, name);
else
Debug.LogWarning($"Skipping SourceAssetIdentifier: name is null or empty"); Type guard
static bool IsValidIdentifierName(string name) => !string.IsNullOrEmpty(name);
Try / catch
try { var id = new AssetImporter.SourceAssetIdentifier(type, name); }
catch (ArgumentNullException ex) when (ex.ParamName == "name")
{ Debug.LogWarning($"Skipped SourceAssetIdentifier: name was null"); } Prevention
- Use string.IsNullOrEmpty to catch both null and empty names
- Validate serialized name fields are present and non-empty before constructing
- Filter blank-named sub-assets from remap lists
When it happens
Trigger: Constructing new SourceAssetIdentifier(type, null) where the name argument is null. This happens when reading a name from serialized data where the name field is absent/null, or from an asset whose .name property was never set and returned null via a custom path.
Common situations: Remap configuration loaded from external files (JSON/XML) where the name field is optional or omitted. Also occurs when iterating sub-assets whose names are null in edge cases (e.g., unnamed scriptable objects or assets created programmatically without a name).
Related errors
- asset
- type
- The name is empty
- Cannot add dependency on invalid path.
- Cannot add source dependency on empty GUID.
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/9a6292f253093056.
Report an issue: GitHub.