{"record":{"id":"09cd4944f9bc8e3f","repo":"CoplayDev/unity-mcp","slug":"could-not-read-faces-from-probuildermesh","errorCode":null,"errorMessage":"Could not read faces from ProBuilderMesh.","messagePattern":"Could not read faces from ProBuilderMesh\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"MCPForUnity/Editor/Tools/ProBuilder/ManageProBuilder.cs","lineNumber":324,"sourceCode":"                    BindingFlags.Static | BindingFlags.Public,\n                    null,\n                    new[] { _proBuilderMeshType },\n                    null);\n                optimizeMethod?.Invoke(null, new object[] { pbMesh });\n            }\n        }\n\n        internal static object GetFacesArray(Component pbMesh)\n        {\n            var facesProperty = _proBuilderMeshType.GetProperty(\"faces\");\n            return facesProperty?.GetValue(pbMesh);\n        }\n\n        internal static Array GetFacesByIndices(Component pbMesh, JToken faceIndicesToken)\n        {\n            var allFaces = GetFacesArray(pbMesh);\n            if (allFaces == null)\n                throw new Exception(\"Could not read faces from ProBuilderMesh.\");\n\n            var facesList = (System.Collections.IList)allFaces;\n\n            if (faceIndicesToken == null)\n            {\n                // Return all faces when no indices specified\n                var allResult = Array.CreateInstance(_faceType, facesList.Count);\n                for (int i = 0; i < facesList.Count; i++)\n                    allResult.SetValue(facesList[i], i);\n                return allResult;\n            }\n\n            var indices = faceIndicesToken.ToObject<int[]>();\n            var result = Array.CreateInstance(_faceType, indices.Length);\n            for (int i = 0; i < indices.Length; i++)\n            {\n                if (indices[i] < 0 || indices[i] >= facesList.Count)\n                    throw new Exception($\"Face index {indices[i]} out of range (0-{facesList.Count - 1}).\");","sourceCodeStart":306,"sourceCodeEnd":342,"githubUrl":"https://github.com/CoplayDev/unity-mcp/blob/c21bf496bca87d54e75bad048563c3adb1782081/MCPForUnity/Editor/Tools/ProBuilder/ManageProBuilder.cs#L306-L342","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Verify the ProBuilder package version is compatible with the tool's expected API (check Unity.ProBuilder package version in Package Manager).","Recreate the ProBuilder shape from scratch using create_shape to ensure a valid initialized mesh.","Check that the ProBuilderMesh component is fully initialized before calling face operations (read its properties first).","If using an older ProBuilder version, update to a version the tool was tested against."],"exampleFix":"// before: calling face ops on a possibly-uninitialized mesh\n// after: recreate the shape, then operate\n// 1. create_shape Cube\n// 2. use the new object's target for face operations","handlingStrategy":"try-catch","validationCode":"// C# — pre-check the faces property is accessible before indexing\nvar facesProp = _proBuilderMeshType.GetProperty(\"faces\");\nif (facesProp == null || facesProp.GetValue(pbMesh) == null)\n    return new ErrorResponse(\"ProBuilderMesh faces are not accessible. Mesh may be uninitialized.\");","typeGuard":null,"tryCatchPattern":"try\n{\n    var faces = GetFacesByIndices(pbMesh, faceIndicesToken);\n}\ncatch (Exception ex) when (ex.Message == \"Could not read faces from ProBuilderMesh.\")\n{\n    return new ErrorResponse(\"Faces unreadable — recreate the ProBuilder shape or verify package version.\");\n}","preventionTips":["Ensure the ProBuilder package version matches what the tool expects.","Recreate shapes from scratch rather than operating on meshes from uncertain origins.","Validate mesh data is non-null before face/edge operations."],"tags":["probuilder","faces","reflection","null-reference","version-mismatch"],"backgroundTag":null,"analyzedSha":"c21bf496bca87d54e75bad048563c3adb1782081","analyzedAt":"2026-08-13T17:36:56.095Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}