{"record":{"id":"4573f9d8fb310be4","repo":"Unity-Technologies/ml-agents","slug":"gridsensorcomponent-received-no-sensors-specify-a","errorCode":null,"errorMessage":"GridSensorComponent received no sensors. Specify at least one observation type (OneHot/Counting) to use grid sensors.If you're overriding GridSensorComponent.GetGridSensors(), return at least one grid sensor.","messagePattern":"GridSensorComponent received no sensors\\. Specify at least one observation type \\(OneHot/Counting\\) to use grid sensors\\.If you're overriding GridSensorComponent\\.GetGridSensors\\(\\), return at least one grid sensor\\.","errorType":"exception","errorClass":"UnityAgentsException","httpStatus":null,"severity":"error","filePath":"com.unity.ml-agents/Runtime/Sensors/GridSensorComponent.cs","lineNumber":222,"sourceCode":"                m_CellScale,\n                m_GridSize,\n                m_RotateWithAgent,\n                m_ColliderMask,\n                gameObject,\n                AgentGameObject,\n                m_DetectableTags,\n                m_InitialColliderBufferSize,\n                m_MaxColliderBufferSize\n            );\n\n            // debug data is positive int value and will trigger data validation exception if SensorCompressionType is not None.\n            m_DebugSensor = new GridSensorBase(\"DebugGridSensor\", m_CellScale, m_GridSize, m_DetectableTags, SensorCompressionType.None);\n            m_GridPerception.RegisterDebugSensor(m_DebugSensor);\n\n            m_Sensors = GetGridSensors().ToList();\n            if (m_Sensors == null || m_Sensors.Count < 1)\n            {\n                throw new UnityAgentsException(\"GridSensorComponent received no sensors. Specify at least one observation type (OneHot/Counting) to use grid sensors.\" +\n                    \"If you're overriding GridSensorComponent.GetGridSensors(), return at least one grid sensor.\");\n            }\n\n            // Only one sensor needs to reference the boxOverlapChecker, so that it gets updated exactly once\n            m_Sensors[0].m_GridPerception = m_GridPerception;\n            foreach (var sensor in m_Sensors)\n            {\n                m_GridPerception.RegisterSensor(sensor);\n            }\n\n            if (ObservationStacks != 1)\n            {\n                var sensors = new ISensor[m_Sensors.Count];\n                for (var i = 0; i < m_Sensors.Count; i++)\n                {\n                    sensors[i] = new StackingSensor(m_Sensors[i], ObservationStacks);\n                }\n                return sensors;","sourceCodeStart":204,"sourceCodeEnd":240,"githubUrl":"https://github.com/Unity-Technologies/ml-agents/blob/3ecb446f75d1e7400eb404c562dc005d3164cffc/com.unity.ml-agents/Runtime/Sensors/GridSensorComponent.cs#L204-L240","documentation":"GridSensorComponent.CreateSensors() requires at least one child grid sensor produced by GetGridSensors(). If none are configured (neither OneHot nor Counting observation types), the component cannot generate observations and throws. This catches components that were added but never configured.","triggerScenarios":"Adding a GridSensorComponent to an agent and leaving the sensor list empty; overriding GetGridSensors() in a subclass and returning an empty list (or forgetting to override so the base returns an empty collection).","commonSituations":"Prototyping: dragging the component on but postponing sensor configuration; subclassing GridSensorComponent for custom sensors but returning an empty list when a condition fails; clearing sensors in the inspector while disabling related features.","solutions":["Add at least one grid sensor in the component's sensor list (OneHot or Counting) via the inspector","In a subclass, make GetGridSensors() return a non-empty list, e.g. yield return new GridSensor(\"myGridSensor\", ...);","If grid sensing is optional, disable/remove the GridSensorComponent instead of leaving it empty","Validate the sensor list at scene load or in an editor script to catch empty configurations before play"],"exampleFix":"// before\nprotected override IEnumerable<GridSensor> GetGridSensors()\n{\n    yield break; // no sensors\n}\n// after\nprotected override IEnumerable<GridSensor> GetGridSensors()\n{\n    yield return new GridSensor(\"TagSensor\", cellScale, gridSize, detectableTags, SensorCompressionType.None);\n}","handlingStrategy":"validation","validationCode":"// Unity C#: before play\nvar sensors = GetGridSensors().ToList();\nif (sensors == null || sensors.Count < 1)\n{\n    Debug.LogError(\"GridSensorComponent needs at least one OneHot/Counting sensor\");\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    component.CreateSensors();\n}\ncatch (UnityAgentsException e) when (e.Message.Contains(\"received no sensors\"))\n{\n    Debug.LogError(\"Configure at least one grid sensor (OneHot/Counting): \" + e.Message);\n}","preventionTips":["Configure at least one OneHot or Counting sensor on every GridSensorComponent","In subclasses, ensure GetGridSensors() always yields at least one sensor","Remove/disable the component entirely when grid sensing is not used"],"tags":["unity","ml-agents","grid-sensor","configuration","empty-list"],"backgroundTag":"missing-required-config","analyzedSha":"3ecb446f75d1e7400eb404c562dc005d3164cffc","analyzedAt":"2026-09-02T16:33:12.832Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}