{"record":{"id":"efcb9aa252f44f00","repo":"Unity-Technologies/ml-agents","slug":"the-number-of-training-areas-that-you-have-specifi","errorCode":null,"errorMessage":"The number of training areas that you have specified exceeds the size of the grid.","messagePattern":"The number of training areas that you have specified exceeds the size of the grid\\.","errorType":"exception","errorClass":"UnityAgentsException","httpStatus":null,"severity":"error","filePath":"com.unity.ml-agents/Runtime/Areas/TrainingAreaReplicator.cs","lineNumber":101,"sourceCode":"            if (Academy.Instance.Communicator != null)\n                numAreas = Academy.Instance.NumAreas;\n\n            var rootNumAreas = Mathf.Pow(numAreas, 1.0f / 3.0f);\n            m_GridSize.x = Mathf.CeilToInt(rootNumAreas);\n            m_GridSize.y = Mathf.CeilToInt(rootNumAreas);\n            var zSize = Mathf.CeilToInt((float)numAreas / (m_GridSize.x * m_GridSize.y));\n            m_GridSize.z = zSize == 0 ? 1 : zSize;\n        }\n\n        /// <summary>\n        /// Adds replicas of the training area to the scene.\n        /// </summary>\n        /// <exception cref=\"UnityAgentsException\"></exception>\n        void AddEnvironments()\n        {\n            if (numAreas > m_GridSize.x * m_GridSize.y * m_GridSize.z)\n            {\n                throw new UnityAgentsException(\"The number of training areas that you have specified exceeds the size of the grid.\");\n            }\n\n            for (int z = 0; z < m_GridSize.z; z++)\n            {\n                for (int y = 0; y < m_GridSize.y; y++)\n                {\n                    for (int x = 0; x < m_GridSize.x; x++)\n                    {\n                        if (m_AreaCount == 0)\n                        {\n                            // Skip this first area since it already exists.\n                            m_AreaCount = 1;\n                        }\n                        else if (m_AreaCount < numAreas)\n                        {\n                            m_AreaCount++;\n                            var area = Instantiate(baseArea, new Vector3(x * separation, y * separation, z * separation), Quaternion.identity);\n                            area.name = m_TrainingAreaName;","sourceCodeStart":83,"sourceCodeEnd":119,"githubUrl":"https://github.com/Unity-Technologies/ml-agents/blob/3ecb446f75d1e7400eb404c562dc005d3164cffc/com.unity.ml-agents/Runtime/Areas/TrainingAreaReplicator.cs#L83-L119","documentation":"TrainingAreaReplicator.AddEnvironments throws UnityAgentsException when numAreas exceeds the total grid capacity m_GridSize.x * m_GridSize.y * m_GridSize.z. The replicator lays out training area copies on a 3D grid and cannot place more areas than there are grid cells.","triggerScenarios":"Setting numAreas (training areas parameter in Training Area Replicator) larger than the product of the grid size dimensions configured on the component, triggered from OnEnable.","commonSituations":"Increasing the training areas count in training config without enlarging the grid; misconfigured TrainingAreaReplicator component values on the training scene prefab.","solutions":["Increase the Grid Size x/y/z values so their product is >= numAreas","Reduce the requested number of training areas to fit within the current grid","Verify the training configuration and component fields match before entering Play Mode"],"exampleFix":"// before\nnumAreas = 100; gridSize = (4, 4, 1); // capacity 16\n// after\nnumAreas = 100; gridSize = (10, 10, 1); // capacity 100","handlingStrategy":"validation","validationCode":"if (numAreas > gridSize.x * gridSize.y * gridSize.z) {\n    Debug.LogError(\"Training areas exceed grid capacity; enlarge grid or reduce areas.\");\n}","typeGuard":null,"tryCatchPattern":"try { replicator.enabled = true; } catch (UnityAgentsException e) { Debug.LogError(e.Message); }","preventionTips":["Keep numAreas <= gridSize.x * gridSize.y * gridSize.z","Adjust grid size whenever training-area count changes","Verify TrainingAreaReplicator fields before Play Mode"],"tags":["unity","ml-agents","training-area","configuration"],"backgroundTag":"invalid-configuration","analyzedSha":"3ecb446f75d1e7400eb404c562dc005d3164cffc","analyzedAt":"2026-09-02T16:33:12.832Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}