Unity-Technologies/ml-agents · error · UnityAgentsException
GridSensorComponent received no sensors. Specify at least on
Error message
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.
What it means
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.
Source
Thrown at com.unity.ml-agents/Runtime/Sensors/GridSensorComponent.cs:222
m_CellScale,
m_GridSize,
m_RotateWithAgent,
m_ColliderMask,
gameObject,
AgentGameObject,
m_DetectableTags,
m_InitialColliderBufferSize,
m_MaxColliderBufferSize
);
// debug data is positive int value and will trigger data validation exception if SensorCompressionType is not None.
m_DebugSensor = new GridSensorBase("DebugGridSensor", m_CellScale, m_GridSize, m_DetectableTags, SensorCompressionType.None);
m_GridPerception.RegisterDebugSensor(m_DebugSensor);
m_Sensors = GetGridSensors().ToList();
if (m_Sensors == null || m_Sensors.Count < 1)
{
throw new UnityAgentsException("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.");
}
// Only one sensor needs to reference the boxOverlapChecker, so that it gets updated exactly once
m_Sensors[0].m_GridPerception = m_GridPerception;
foreach (var sensor in m_Sensors)
{
m_GridPerception.RegisterSensor(sensor);
}
if (ObservationStacks != 1)
{
var sensors = new ISensor[m_Sensors.Count];
for (var i = 0; i < m_Sensors.Count; i++)
{
sensors[i] = new StackingSensor(m_Sensors[i], ObservationStacks);
}
return sensors;View on GitHub (pinned to 3ecb446f75)
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
Example fix
// before
protected override IEnumerable<GridSensor> GetGridSensors()
{
yield break; // no sensors
}
// after
protected override IEnumerable<GridSensor> GetGridSensors()
{
yield return new GridSensor("TagSensor", cellScale, gridSize, detectableTags, SensorCompressionType.None);
} Defensive patterns
Strategy: validation
Validate before calling
// Unity C#: before play
var sensors = GetGridSensors().ToList();
if (sensors == null || sensors.Count < 1)
{
Debug.LogError("GridSensorComponent needs at least one OneHot/Counting sensor");
} Try / catch
try
{
component.CreateSensors();
}
catch (UnityAgentsException e) when (e.Message.Contains("received no sensors"))
{
Debug.LogError("Configure at least one grid sensor (OneHot/Counting): " + e.Message);
} Prevention
- 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
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
Background: "X is required", "must be set", "cannot be empty": the missing-required-config error family, from Vertex AI project/location to WeChat keys — this error's family across 18 libraries.
Related errors
- GridSensor only supports 2D grids.
- Action spaces with both continuous and discrete actions are
- The number of training areas that you have specified exceeds
- Can't use Behavior Type {behaviorType} without a model. Eith
- When using compression type {m_CompressionType} the data val
AI-assisted analysis of Unity-Technologies/ml-agents@3ecb446f75 (2026-09-02).
Data as JSON: /api/errors/4573f9d8fb310be4.
Report an issue: GitHub.