CoplayDev/unity-mcp · error · Exception

Could not read faces from ProBuilderMesh.

Error message

Could not read faces from ProBuilderMesh.

What it means

Thrown by GetFacesByIndices when GetFacesArray returns null. GetFacesArray reads the 'faces' property of the ProBuilderMesh via reflection (_proBuilderMeshType.GetProperty('faces')). A null result means the reflection lookup failed or the mesh has no faces data — typically a corrupted or uninitialized ProBuilderMesh.

Source

Thrown at MCPForUnity/Editor/Tools/ProBuilder/ManageProBuilder.cs:324

                    BindingFlags.Static | BindingFlags.Public,
                    null,
                    new[] { _proBuilderMeshType },
                    null);
                optimizeMethod?.Invoke(null, new object[] { pbMesh });
            }
        }

        internal static object GetFacesArray(Component pbMesh)
        {
            var facesProperty = _proBuilderMeshType.GetProperty("faces");
            return facesProperty?.GetValue(pbMesh);
        }

        internal static Array GetFacesByIndices(Component pbMesh, JToken faceIndicesToken)
        {
            var allFaces = GetFacesArray(pbMesh);
            if (allFaces == null)
                throw new Exception("Could not read faces from ProBuilderMesh.");

            var facesList = (System.Collections.IList)allFaces;

            if (faceIndicesToken == null)
            {
                // Return all faces when no indices specified
                var allResult = Array.CreateInstance(_faceType, facesList.Count);
                for (int i = 0; i < facesList.Count; i++)
                    allResult.SetValue(facesList[i], i);
                return allResult;
            }

            var indices = faceIndicesToken.ToObject<int[]>();
            var result = Array.CreateInstance(_faceType, indices.Length);
            for (int i = 0; i < indices.Length; i++)
            {
                if (indices[i] < 0 || indices[i] >= facesList.Count)
                    throw new Exception($"Face index {indices[i]} out of range (0-{facesList.Count - 1}).");

View on GitHub (pinned to c21bf496bc)

Solutions

  1. Verify the ProBuilder package version is compatible with the tool's expected API (check Unity.ProBuilder package version in Package Manager).
  2. Recreate the ProBuilder shape from scratch using create_shape to ensure a valid initialized mesh.
  3. Check that the ProBuilderMesh component is fully initialized before calling face operations (read its properties first).
  4. If using an older ProBuilder version, update to a version the tool was tested against.

Example fix

// before: calling face ops on a possibly-uninitialized mesh
// after: recreate the shape, then operate
// 1. create_shape Cube
// 2. use the new object's target for face operations
Defensive patterns

Strategy: try-catch

Validate before calling

// C# — pre-check the faces property is accessible before indexing
var facesProp = _proBuilderMeshType.GetProperty("faces");
if (facesProp == null || facesProp.GetValue(pbMesh) == null)
    return new ErrorResponse("ProBuilderMesh faces are not accessible. Mesh may be uninitialized.");

Try / catch

try
{
    var faces = GetFacesByIndices(pbMesh, faceIndicesToken);
}
catch (Exception ex) when (ex.Message == "Could not read faces from ProBuilderMesh.")
{
    return new ErrorResponse("Faces unreadable — recreate the ProBuilder shape or verify package version.");
}

Prevention

When it happens

Trigger: Calling a ProBuilder face operation (get_faces, delete_faces, etc.) on a ProBuilderMesh whose internal faces array is null or inaccessible. Happens when the mesh was created by reflection but never properly initialized, or the ProBuilder API version changed the property name/type.

Common situations: ProBuilder package version mismatch where the 'faces' property was renamed or restructured; mesh was partially created and left in an invalid state; ProBuilderMesh exists but was never assigned geometry.

Related errors


AI-assisted analysis of CoplayDev/unity-mcp@c21bf496bc (2026-08-13). Data as JSON: /api/errors/09cd4944f9bc8e3f. Report an issue: GitHub.