{"record":{"id":"b90bf3a82649d3eb","repo":"egametang/ET","slug":"rcbuildcompactheightfield-heightfield-has-too-man","errorCode":null,"errorMessage":"rcBuildCompactHeightfield: Heightfield has too many layers {tooHighNeighbour} (max: {MAX_LAYERS})","messagePattern":"rcBuildCompactHeightfield: Heightfield has too many layers (.+?) \\(max: (.+?)\\)","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"warning","filePath":"Packages/cn.etetet.recast/Scripts/Core/Share/Recast/RecastCompact.cs","lineNumber":159,"sourceCode":"                                    int lidx = k - nc.index;\n                                    if (lidx < 0 || lidx > MAX_LAYERS)\n                                    {\n                                        tooHighNeighbour = Math.Max(tooHighNeighbour, lidx);\n                                        continue;\n                                    }\n\n                                    RecastCommon.SetCon(s, dir, lidx);\n                                    break;\n                                }\n                            }\n                        }\n                    }\n                }\n            }\n\n            if (tooHighNeighbour > MAX_LAYERS)\n            {\n                throw new Exception(\"rcBuildCompactHeightfield: Heightfield has too many layers \" + tooHighNeighbour\n                                                                                                  + \" (max: \" + MAX_LAYERS + \")\");\n            }\n\n            return chf;\n        }\n\n        private static int GetHeightFieldSpanCount(RcHeightfield hf)\n        {\n            int w = hf.width;\n            int h = hf.height;\n            int spanCount = 0;\n            for (int y = 0; y < h; ++y)\n            {\n                for (int x = 0; x < w; ++x)\n                {\n                    for (RcSpan s = hf.spans[x + y * w]; s != null; s = s.next)\n                    {\n                        if (s.area != RC_NULL_AREA)","sourceCodeStart":141,"sourceCodeEnd":177,"githubUrl":"https://github.com/egametang/ET/blob/5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f/Packages/cn.etetet.recast/Scripts/Core/Share/Recast/RecastCompact.cs#L141-L177","documentation":"Thrown at the end of rcBuildCompactHeightfield when a compact-cell neighbour span index (lidx) exceeded MAX_LAYERS during neighbour connectivity. MAX_LAYERS caps how many overlapping walkable spans can stack in a single XZ cell of the compact heightfield; exceeding it means the voxelization produced too many stacked walkable layers for the configuration.","triggerScenarios":"A scene with many overlapping walkable surfaces in the same column (stairs, ramps, thin floors) combined with a small walkableHeight and/or large voxel cell size that stacks spans; geometry with near-coincident walkable planes.","commonSituations":"Cell height too large relative to floor spacing; walkableHeight too small so multiple thin ledges each qualify as walkable; dense multi-floor geometry.","solutions":["Increase walkableHeight so closely-stacked spans merge into fewer layers.","Decrease voxel cell size (cs) / cell height (ch) to better separate the layers spatially.","Increase walkableClimb to merge small steps that spawn extra layers.","Simplify the source geometry to remove redundant overlapping walkable surfaces."],"exampleFix":"// before\ncfg.walkableHeight = 0.1f; // tiny -> many stacked spans\ncfg.cs = 0.3f;\n\n// after\ncfg.walkableHeight = 1.5f; // merge thin layers\ncfg.cs = 0.2f;            // finer voxels separate real layers","handlingStrategy":"validation","validationCode":"// Sanity-check config before building.\nif (cfg.walkableHeight < cfg.ch * 2) Debug.LogWarning(\"walkableHeight very small -> many layers\");\nif (cfg.ch > cfg.walkableHeight) Debug.LogWarning(\"cell height > walkableHeight may stack layers\");","typeGuard":"// No type guard (config-tuning). Treat as runtime config validation.","tryCatchPattern":"try { RcCompactHeightfield chf = RecastCompact.BuildCompactHeightfield(ctx, walkableHeight, walkableClimb, hf); }\ncatch (Exception e) when (e.Message.Contains(\"too many layers\"))\n{ /* raise walkableHeight / lower cs,ch and retry */ }","preventionTips":["Increase walkableHeight to merge closely-stacked spans.","Decrease cell size/height for finer vertical separation.","Increase walkableClimb to absorb small steps.","Simplify geometry with many overlapping walkable surfaces."],"tags":["recast","compact-heightfield","config","voxelization"],"backgroundTag":null,"analyzedSha":"5cab01f7a8bee5f49f4781eebe9e2b1c6d7ebe0f","analyzedAt":"2026-08-13T21:10:40.377Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}