Unity-Technologies/ml-agents · error · UnityTrainerException

The trainer was unable to process any of the provided inputs

Error message

The trainer was unable to process any of the provided inputs. Make sure the trained agents has at least one sensor attached to them.

What it means

Networks.py raises UnityTrainerException in the MultiInputNetwork forward pass when, after processing all sensors, no input was actually encoded (input_exist stays False). ML-Agents requires an agent to contribute at least one sensor (visual or vector observation) so the network can build an encoding; with zero usable sensors the cat() over an empty collection would be meaningless, so the library fails fast.

Source

Thrown at ml-agents/mlagents/trainers/torch_entities/networks.py:144

            masks = get_zero_entities_mask([p_i[1] for p_i in var_len_processor_inputs])
            embeddings: List[torch.Tensor] = []
            processed_self = (
                self.x_self_encoder(encoded_self)
                if input_exist and self.x_self_encoder is not None
                else None
            )
            for processor, var_len_input in var_len_processor_inputs:
                embeddings.append(processor(processed_self, var_len_input))
            qkv = torch.cat(embeddings, dim=1)
            attention_embedding = self.rsa(qkv, masks)
            if not input_exist:
                encoded_self = torch.cat([attention_embedding], dim=1)
                input_exist = True
            else:
                encoded_self = torch.cat([encoded_self, attention_embedding], dim=1)

        if not input_exist:
            raise UnityTrainerException(
                "The trainer was unable to process any of the provided inputs. "
                "Make sure the trained agents has at least one sensor attached to them."
            )

        return encoded_self

    def get_goal_encoding(self, inputs: List[torch.Tensor]) -> torch.Tensor:
        """
        Encode observations corresponding to goals using a list of processors.
        :param inputs: List of Tensors corresponding to a set of obs.
        """
        encodes = []
        for idx in self._goal_processor_indices:
            processor = self.processors[idx]
            if not isinstance(processor, EntityEmbedding):
                # The input can be encoded without having to process other inputs
                obs_input = inputs[idx]
                processed_obs = processor(obs_input)

View on GitHub (pinned to 3ecb446f75)

Solutions

  1. Attach at least one sensor (CameraSensorComponent, RenderTextureSensorComponent, or ObservationProvider) to the agent or ensure the BehaviorSpec has at least one observation spec
  2. If using vector observations, verify the Behavior Parameters 'Vector Observation' Space Size is > 0 in Unity
  3. Check that custom sensors are actually added to the Agent (sensors list) and are discovered by ML-Agents
  4. Verify your training config's behavior name matches the one emitted by the environment so the correct spec with sensors is used

Example fix

// before (Python, agent setup)
agent = Agent()
// after
agent = Agent()
agent.add_component(CameraSensorComponent(...))
# or in Unity: Behavior Parameters > Vector Observation Space Size = 8
Defensive patterns

Strategy: validation

Validate before calling

from mlagents_envs.base_env import BehaviorSpec
assert behavior_spec.observation_specs, "Agent must have at least one observation sensor"
for spec in behavior_spec.observation_specs:
    assert spec.shape, f"Observation {spec} has empty shape"

Type guard

def has_sensors(behavior_spec) -> bool:
    return len(behavior_spec.observation_specs) > 0

Try / catch

from mlagents.trainers.exception import UnityTrainerException
try:
    encoding = network.forward(inputs)
except UnityTrainerException as e:
    logger.error(f"Agent has no sensors: {e}")
    raise

Prevention

When it happens

Trigger: Calling forward on a network whose behavior/agent has no sensors attached (no camera SensorComponents, no vector observations), so the loop over sensors never sets input_exist=True.

Common situations: Training an agent whose behavior spec has zero observation sensors; a custom training script constructing a NetworkBody/actor from an empty BehaviorSpec; a Unity scene where the Behavior Parameters were set but observations were removed or the sensor registration failed.

Related errors


AI-assisted analysis of Unity-Technologies/ml-agents@3ecb446f75 (2026-09-02). Data as JSON: /api/errors/e8f6ba28d5e8d2cb. Report an issue: GitHub.