{"record":{"id":"5ce04a03a59ee491","repo":"Unity-Technologies/ml-agents","slug":"gridsensor-only-supports-2d-grids","errorCode":null,"errorMessage":"GridSensor only supports 2D grids.","messagePattern":"GridSensor only supports 2D grids\\.","errorType":"exception","errorClass":"UnityAgentsException","httpStatus":null,"severity":"error","filePath":"com.unity.ml-agents/Runtime/Sensors/GridSensorBase.cs","lineNumber":73,"sourceCode":"        /// <param name=\"detectableTags\">Tags to be detected by the sensor</param>\n        /// <param name=\"compression\">Compression type</param>\n        public GridSensorBase(\n            string name,\n            Vector3 cellScale,\n            Vector3Int gridSize,\n            string[] detectableTags,\n            SensorCompressionType compression\n        )\n        {\n            m_Name = name;\n            m_CellScale = cellScale;\n            m_GridSize = gridSize;\n            m_DetectableTags = detectableTags;\n            CompressionType = compression;\n\n            if (m_GridSize.y != 1)\n            {\n                throw new UnityAgentsException(\"GridSensor only supports 2D grids.\");\n            }\n\n            m_NumCells = m_GridSize.x * m_GridSize.z;\n            m_CellObservationSize = GetCellObservationSize();\n            m_ObservationSpec = ObservationSpec.Visual(m_CellObservationSize, m_GridSize.x, m_GridSize.z);\n            m_PerceptionTexture = new Texture2D(m_GridSize.x, m_GridSize.z, TextureFormat.RGB24, false);\n\n            ResetPerceptionBuffer();\n        }\n\n        /// <summary>\n        /// The compression type used by the sensor.\n        /// </summary>\n        public SensorCompressionType CompressionType\n        {\n            get { return m_CompressionType; }\n            set\n            {","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/Unity-Technologies/ml-agents/blob/3ecb446f75d1e7400eb404c562dc005d3164cffc/com.unity.ml-agents/Runtime/Sensors/GridSensorBase.cs#L55-L91","documentation":"GridSensorBase's constructor only accepts grid sizes whose Y dimension is 1, i.e. flat 2D grids in the XZ plane. A grid with Y != 1 (a 3D volume) has no supported implementation and is rejected at construction time before any observation is produced.","triggerScenarios":"Constructing GridSensorBase (or subclass) with a gridSize Vector3 whose .y is not 1; configuring GridSensorComponent's GridSize Y field to a value other than 1 in the inspector.","commonSituations":"Attempting to build a 3D volumetric detection grid for flying/drone agents; copy-pasting a Vector3 size (e.g. (10, 5, 10)) meant for spatial bounds directly into grid size.","solutions":["Set the grid size Y component to 1, keeping detection in the XZ plane (e.g. Vector3(10, 1, 10))","Move vertical detection into the detected-object filtering logic or cell data rather than extra grid layers","If 3D volumes are truly required, implement a custom SensorBase instead of GridSensorBase"],"exampleFix":"// before\nnew GridSensorBase(\"grid\", cellScale, new Vector3(10, 5, 10), tags, compression);\n// after\nnew GridSensorBase(\"grid\", cellScale, new Vector3(10, 1, 10), tags, compression);","handlingStrategy":"validation","validationCode":"// Unity C#: before constructing the sensor\nif (gridSize.y != 1)\n{\n    Debug.LogError($\"GridSensor requires gridSize.y == 1, got {gridSize.y}\");\n    gridSize = new Vector3(gridSize.x, 1, gridSize.z);\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    var sensor = new GridSensorBase(\"grid\", cellScale, gridSize, tags, compression);\n}\ncatch (UnityAgentsException e) when (e.Message.Contains(\"only supports 2D grids\"))\n{\n    Debug.LogError(\"Set grid size Y to 1: \" + e.Message);\n}","preventionTips":["Always set grid size Y to 1 (e.g. Vector3(10, 1, 10))","Handle vertical detection via filtering/cell data, not extra Y layers","Validate grid size in Awake before sensor construction"],"tags":["unity","ml-agents","grid-sensor","configuration"],"backgroundTag":"unsupported-grid-dimension","analyzedSha":"3ecb446f75d1e7400eb404c562dc005d3164cffc","analyzedAt":"2026-09-02T16:33:12.832Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}