Unity-Technologies/UnityCsReference · error · ArgumentNullException

name

Error message

name

What it means

Same AssetIdentifier(Type, string) constructor, second guard: the name argument cannot be null because the identifier is keyed on it for material/asset remapping, and a null name would produce an unmatchable entry. Throwing ArgumentNullException at construction makes the contract explicit instead of letting null propagate into dictionary lookups and equality comparisons.

Source

Thrown at Editor/Mono/AssetPipeline/SpeedTree/SpeedTreeImporterSettings.cs:159

            if (asset == null)
            {
                throw new ArgumentNullException("asset");
            }

            this.type = asset.GetType().ToString();
            this.name = asset.name;
        }

        public AssetIdentifier(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.ToString();
            this.name = name;
        }
    }

    /// <summary>
    /// This attribute is used as a callback to set SRP specific properties from the importer.
    /// </summary>
    [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)]
    public class MaterialSettingsCallbackAttribute : Attribute
    {

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Supply a non-null name; if the source can legitimately be missing, default it to a stable sentinel like string.Empty only if an empty name is acceptable (note: error 42 will then reject empty).
  2. Validate name != null at the call site and surface a clear error naming the offending asset.
  3. Ensure upstream asset naming is populated before identifiers are constructed (e.g. set asset.name during import).

Example fix

// before
var id = new AssetIdentifier(type, asset.name); // asset.name may be null

// after
if (asset.name == null)
    throw new InvalidOperationException("Asset has no name: " + asset);
var id = new AssetIdentifier(type, asset.name);
Defensive patterns

Strategy: validation

Validate before calling

string RequireName(string name) {
    if (name == null)
        throw new InvalidOperationException("Asset name is null.");
    return name;
}
// then: new AssetIdentifier(type, RequireName(asset.name));

Type guard

static bool HasName(string name) => name != null;

Prevention

When it happens

Trigger: Calling new AssetIdentifier(someType, null); passing a name read from an asset whose .name field was never set or was explicitly cleared; feeding a name from a nullable config property that defaulted to null.

Common situations: Assets imported before being named; config-driven identifier creation with an optional/missing name field; refactor that changed where the name originates.

Related errors


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