{"record":{"id":"2857ab11dec45677","repo":"Unity-Technologies/ml-agents","slug":"there-are-no-observations-provided-by-the-environm","errorCode":null,"errorMessage":"There are no observations provided by the environment.","messagePattern":"There are no observations provided by the environment\\.","errorType":"exception","errorClass":"UnityGymException","httpStatus":null,"severity":"error","filePath":"ml-agents-envs/mlagents_envs/envs/unity_gym_env.py","lineNumber":77,"sourceCode":"        # Save the step result from the last time all Agents requested decisions.\n        self._previous_decision_step: Optional[DecisionSteps] = None\n        self._flattener = None\n        # Hidden flag used by Atari environments to determine if the game is over\n        self.game_over = False\n        self._allow_multiple_obs = allow_multiple_obs\n\n        # Check brain configuration\n        if len(self._env.behavior_specs) != 1:\n            raise UnityGymException(\n                \"There can only be one behavior in a UnityEnvironment \"\n                \"if it is wrapped in a gym.\"\n            )\n\n        self.name = list(self._env.behavior_specs.keys())[0]\n        self.group_spec = self._env.behavior_specs[self.name]\n\n        if self._get_n_vis_obs() == 0 and self._get_vec_obs_size() == 0:\n            raise UnityGymException(\n                \"There are no observations provided by the environment.\"\n            )\n\n        if not self._get_n_vis_obs() >= 1 and uint8_visual:\n            logger.warning(\n                \"uint8_visual was set to true, but visual observations are not in use. \"\n                \"This setting will not have any effect.\"\n            )\n        else:\n            self.uint8_visual = uint8_visual\n        if (\n            self._get_n_vis_obs() + self._get_vec_obs_size() >= 2\n            and not self._allow_multiple_obs\n        ):\n            logger.warning(\n                \"The environment contains multiple observations. \"\n                \"You must define allow_multiple_obs=True to receive them all. \"\n                \"Otherwise, only the first visual observation (or vector observation if\"","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/Unity-Technologies/ml-agents/blob/3ecb446f75d1e7400eb404c562dc005d3164cffc/ml-agents-envs/mlagents_envs/envs/unity_gym_env.py#L59-L95","documentation":"UnityGymException thrown by UnityGymEnv.__init__ when the environment's single behavior provides neither visual observations (n_vis_obs == 0) nor vector observations (vec_obs_size == 0). The gym wrapper must expose at least one observation space.","triggerScenarios":"Wrapping a UnityEnvironment whose behavior spec declares no sensors and no vector observation space (Agent has no Sensor components and no VectorSensor configured).","commonSituations":"Unity scene where the Agent GameObject has no Camera/Raycast/CollectObservations contributions; building an executable from an empty training scene; mismatched environment binary without observation setup.","solutions":["Add at least one Sensor (e.g. CameraSensor or ObservationSensor / implement CollectObservations writing to a VectorSensor) to the Agent in the Unity scene.","Rebuild the executable after adding the sensor.","Inspect group_spec before wrapping: check _get_n_vis_obs() / _get_vec_obs_size() equivalents via behavior_specs observation specs.","If observations exist but under a different behavior, resolve error 50 first (multiple behaviors)."],"exampleFix":"// before\nenv = UnityGymEnv(env_with_no_sensors)\n// after\n# In Unity: add a CameraSensor or VectorSensor to the Agent, rebuild, then:\nenv = UnityGymEnv(UnityEnvironment(file_name='rebuilt_app'))","handlingStrategy":"validation","validationCode":"spec = next(iter(unity_env.behavior_specs.values()))\nvis = sum(len(spec.observation_specs) and 1 for o in spec.observation_specs if any(d >= 3 for d in o.shape))\nvec = sum(int(np.prod(o.shape)) for o in spec.observation_specs if all(d < 3 for d in o.shape))\nif vis == 0 and vec == 0:\n    raise ValueError(\"Behavior provides no observations\")\nenv = UnityGymEnv(unity_env)","typeGuard":"def has_observations(group_spec) -> bool:\n    return len(group_spec.observation_specs) > 0","tryCatchPattern":"try:\n    env = UnityGymEnv(unity_env)\nexcept UnityGymException:\n    raise RuntimeError(\"Unity build exposes no sensors/observations; add a sensor to the Agent\")","preventionTips":["Ensure the Agent has at least one sensor in Unity","Test-wrap the environment right after each build","Inspect behavior_specs observation_specs before wrapping"],"tags":["gym","unity-environment","observations"],"backgroundTag":"missing-observations-space","analyzedSha":"3ecb446f75d1e7400eb404c562dc005d3164cffc","analyzedAt":"2026-09-02T16:33:12.832Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}