Unity-Technologies/UnityCsReference · error · ArgumentNullException
Mesh array is null
Error message
Mesh array is null
What it means
Thrown by the Mesh[] overload of AcquireReadOnlyMeshData when the meshes array is null. The method acquires read-only CPU access to the mesh vertex/index data of multiple meshes and requires a non-null array.
Source
Thrown at Editor/Mono/MeshUtility.bindings.cs:59
if (uvCount != 3 * triCount)
{
Debug.LogError("mesh contains " + triCount + " triangles but " + uvCount + " uvs are provided");
return false;
}
return SetPerTriangleUV2NoCheck(src, triUV);
}
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
- Allocate and populate the array before calling; if no meshes exist, handle that case explicitly rather than passing null.
- Null-check the array and log which source produced null.
- Use the List<Mesh> overload if you already have a list, to avoid manual array management.
Example fix
// before var data = MeshUtility.AcquireReadOnlyMeshData(meshes); // after if (meshes == null || meshes.Length == 0) return; var data = MeshUtility.AcquireReadOnlyMeshData(meshes);
Defensive patterns
Strategy: type-guard
Validate before calling
if (meshes == null || meshes.Length == 0) return;
Type guard
static bool HasMeshes(Mesh[] m) => m != null && m.Length > 0;
Try / catch
try { var data = MeshUtility.AcquireReadOnlyMeshData(meshes); }
catch (ArgumentNullException ex) when (ex.ParamName == "meshes") { Debug.LogWarning("No meshes to acquire."); } Prevention
- Allocate the array before calling
- Handle the no-meshes case explicitly
- Prefer the List overload when applicable
When it happens
Trigger: Calling AcquireReadOnlyMeshData((Mesh[])null), or passing an array reference that was never allocated. Distinct from the single-Mesh overload and the List<Mesh> overload, which have their own null checks.
Common situations: Editor tooling that collects meshes from a hierarchy and passes the result without checking for null (e.g. when no meshes were found). A field defaulting to null passed directly.
Related errors
AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13).
Data as JSON: /api/errors/a99ddfe5bf6df271.
Report an issue: GitHub.