{"record":{"id":"cdc16d22bde20735","repo":"CoplayDev/unity-mcp","slug":"edge-index-idx-out-of-range-0-alledges-count","errorCode":null,"errorMessage":"Edge index {idx} out of range (0-{allEdges.Count - 1}).","messagePattern":"Edge index (.+?) out of range \\(0-(.+?)\\)\\.","errorType":"validation","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"MCPForUnity/Editor/Tools/ProBuilder/ManageProBuilder.cs","lineNumber":518,"sourceCode":"            if (edgePairsToken != null && edgePairsToken.Type == JTokenType.Array)\n            {\n                // Edge specification by vertex pairs: [{a: 0, b: 1}, ...]\n                foreach (var pair in edgePairsToken)\n                {\n                    int a = pair[\"a\"]?.Value<int>() ?? 0;\n                    int b = pair[\"b\"]?.Value<int>() ?? 0;\n                    edgeList.Add(CreateEdge(a, b));\n                }\n            }\n            else if (edgeIndicesToken != null)\n            {\n                // Edge specification by index into unique edges\n                var allEdges = CollectUniqueEdges(pbMesh);\n                var edgeIndices = edgeIndicesToken.ToObject<int[]>();\n                foreach (int idx in edgeIndices)\n                {\n                    if (idx < 0 || idx >= allEdges.Count)\n                        throw new Exception($\"Edge index {idx} out of range (0-{allEdges.Count - 1}).\");\n                    edgeList.Add(allEdges[idx]);\n                }\n            }\n            else\n            {\n                throw new Exception(\"edgeIndices or edges parameter is required.\");\n            }\n\n            count = edgeList.Count;\n            var edgeArray = Array.CreateInstance(_edgeType, edgeList.Count);\n            for (int i = 0; i < edgeList.Count; i++)\n                edgeArray.SetValue(edgeList[i], i);\n            return edgeArray;\n        }\n\n        /// <summary>\n        /// Create a typed List&lt;Edge&gt; from an Edge[] array for APIs that require IList&lt;Edge&gt;.\n        /// </summary>","sourceCodeStart":500,"sourceCodeEnd":536,"githubUrl":"https://github.com/CoplayDev/unity-mcp/blob/c21bf496bca87d54e75bad048563c3adb1782081/MCPForUnity/Editor/Tools/ProBuilder/ManageProBuilder.cs#L500-L536","documentation":"Thrown by ResolveEdges when an edge index in 'edgeIndices' is negative or exceeds the mesh's unique edge count. Unique edges are collected by CollectUniqueEdges from the ProBuilderMesh. The valid range is 0 to (edgeCount - 1).","triggerScenarios":"Passing edgeIndices referencing edges that don't exist on the mesh. Common when the mesh has fewer edges than expected, or indices are stale after topology changes. Note: edge count differs from face count — a cube has 18 unique edges, not 6.","commonSituations":"AI confuses face indices with edge indices; edge list collected from a different mesh state; ProBuilder's edge enumeration changed after bevel/extrude operations; off-by-one or negative index errors.","solutions":["Enumerate edges first (call a get/read edges operation) to discover valid edge indices and the total count.","Re-fetch edge indices after any topology-modifying operation before referencing them.","Consider specifying edges as vertex pairs {a, b} instead of indices, which are more stable across topology changes.","Validate every index is within [0, edgeCount-1] before the call."],"exampleFix":"// before\nparams = {\"target\": \"MyShape\", \"edgeIndices\": [0, 1, 100]}\n// after: use vertex pairs which are independent of edge enumeration order\nparams = {\"target\": \"MyShape\", \"edges\": [{\"a\": 0, \"b\": 1}, {\"a\": 2, \"b\": 3}]}","handlingStrategy":"validation","validationCode":"# Before calling an edge operation, enumerate unique edges to get the count\ndef validate_edge_indices(indices: list, edge_count: int) -> bool:\n    return all(0 <= i < edge_count for i in indices)\n\n# Prefer vertex-pair specification to avoid index instability","typeGuard":null,"tryCatchPattern":"try\n{\n    var edges = ResolveEdges(pbMesh, props, out int count);\n}\ncatch (Exception ex) when (ex.Message.Contains(\"Edge index\") && ex.Message.Contains(\"out of range\"))\n{\n    return new ErrorResponse(ex.Message);\n}","preventionTips":["Prefer vertex pairs {a, b} over edge indices — they survive topology changes better.","Enumerate edges before indexing into them.","Never assume edge count equals face count or vertex count.","Re-fetch edge indices after any structural mesh edit."],"tags":["probuilder","edges","index-out-of-range","validation","bounds-check"],"backgroundTag":null,"analyzedSha":"c21bf496bca87d54e75bad048563c3adb1782081","analyzedAt":"2026-08-13T17:36:56.095Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}