Unity-Technologies/UnityCsReference · error · ArgumentNullException

Mesh list is null

Error message

Mesh list is null

What it means

Thrown by the List<Mesh> overload of AcquireReadOnlyMeshData when the meshes list is null. It mirrors the array overload's null check before extracting the internal array via NoAllocHelpers.ExtractArrayFromList.

Source

Thrown at Editor/Mono/MeshUtility.bindings.cs:66

        extern internal static Vector2[] ComputeTextureBoundingHull(Texture texture, int vertexCount);

        public static Mesh.MeshDataArray AcquireReadOnlyMeshData(Mesh mesh)
        {
            return new Mesh.MeshDataArray(mesh, false);
        }

        public static Mesh.MeshDataArray AcquireReadOnlyMeshData(Mesh[] meshes)
        {
            if (meshes == null)
                throw new ArgumentNullException(nameof(meshes), "Mesh array is null");
            return new Mesh.MeshDataArray(meshes, meshes.Length, false);
        }

        public static Mesh.MeshDataArray AcquireReadOnlyMeshData(List<Mesh> meshes)
        {
            if (meshes == null)
                throw new ArgumentNullException(nameof(meshes), "Mesh list is null");
            return new Mesh.MeshDataArray(NoAllocHelpers.ExtractArrayFromList(meshes), meshes.Count, false);
        }
    }
}

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Initialize the list (new List<Mesh>()) before calling, or skip the call when no meshes are available.
  2. Null-check the list and surface a clearer error identifying the source.
  3. Prefer passing an empty list over null to distinguish 'no meshes' from 'uninitialized'.

Example fix

// before
var data = MeshUtility.AcquireReadOnlyMeshData(meshList);

// after
if (meshList == null) meshList = new List<Mesh>();
if (meshList.Count == 0) return;
var data = MeshUtility.AcquireReadOnlyMeshData(meshList);
Defensive patterns

Strategy: type-guard

Validate before calling

if (meshes == null) meshes = new List<Mesh>();
if (meshes.Count == 0) return;

Type guard

static bool HasMeshes(List<Mesh> m) => m != null && m.Count > 0;

Try / catch

try { var data = MeshUtility.AcquireReadOnlyMeshData(meshes); }
catch (ArgumentNullException ex) when (ex.ParamName == "meshes") { Debug.LogWarning("No mesh list provided."); }

Prevention

When it happens

Trigger: Calling AcquireReadOnlyMeshData((List<Mesh>)null), or passing a list field that was never initialized. Note the single-Mesh and array overloads have separate checks.

Common situations: Editor tooling that builds a List<Mesh> conditionally and passes the uninitialized field when the branch was not taken.

Related errors


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