Unity-Technologies/UnityCsReference · error · ArgumentNullException

asset

Error message

asset

What it means

SpeedTreeImporterSettings.AssetIdentifier(Object asset) constructor creates an identifier from a Unity Object's type and name for SpeedTree asset remapping. It throws ArgumentNullException with param name 'asset' when the passed Object is null, because it needs asset.GetType().ToString() and asset.name to populate the type and name fields. This mirrors the SourceAssetIdentifier pattern (error 33) but uses string type names instead of System.Type.

Source

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

        [Range(0.0f, 1.0f)]
        public float randomness = 0.5f;
    }

    // Ideally, we should use 'AssetImporter.SourceAssetIdentifier', but this struct has many problems:
    // 1 - 'Type' is not a serializable type, so it's always equal to null in our context.
    // 2 - The C# struct is not matching the C++ class.
    // 3 - Missing the 'Serializable' attribute on top of the struct.
    [Serializable]
    internal class AssetIdentifier
    {
        public string type;
        public string name;

        public AssetIdentifier(UnityEngine.Object asset)
        {
            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");
            }

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Null-check before constructing: if (asset != null) new AssetIdentifier(asset).
  2. Use the (Type, string) overload if available and you have type/name without needing the Object.
  3. Validate loaded assets with a null check and type check before constructing identifiers.

Example fix

// before
var id = new AssetIdentifier(loadedMaterial);

// after
if (loadedMaterial != null)
    var id = new AssetIdentifier(loadedMaterial);
else
    Debug.LogWarning("Cannot create SpeedTree AssetIdentifier: asset is null");
Defensive patterns

Strategy: validation

Validate before calling

if (asset != null)
    var id = new AssetIdentifier(asset);
else
    Debug.LogWarning("Cannot create SpeedTree AssetIdentifier: null asset");

Type guard

static bool IsValidUnityObject(Object obj) => obj != null;

Try / catch

try { var id = new AssetIdentifier(asset); }
catch (ArgumentNullException ex) when (ex.ParamName == "asset")
{ Debug.LogWarning($"Skipped AssetIdentifier: {ex.Message}"); }

Prevention

When it happens

Trigger: Constructing new AssetIdentifier(obj) where obj is null. This happens when loading a material, mesh, or texture for SpeedTree remapping returns null due to a failed load, wrong type cast, or unimported asset, and the null is passed directly.

Common situations: SpeedTree material/geometry remap utilities, editor scripts that build AssetIdentifier lists from loaded sub-assets. The null arises from AssetDatabase.LoadAssetAtPath returning null on missing assets, type mismatches, or assets pending import.

Related errors


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