{"record":{"id":"12e0fc866109498e","repo":"Unity-Technologies/ml-agents","slug":"the-one-of-the-goals-uses-variable-length-observat","errorCode":null,"errorMessage":"The one of the goals uses variable length observations. This use case is not supported.","messagePattern":"The one of the goals uses variable length observations\\. This use case is not supported\\.","errorType":"exception","errorClass":"UnityTrainerException","httpStatus":null,"severity":"error","filePath":"ml-agents/mlagents/trainers/torch_entities/networks.py","lineNumber":165,"sourceCode":"            )\n\n        return encoded_self\n\n    def get_goal_encoding(self, inputs: List[torch.Tensor]) -> torch.Tensor:\n        \"\"\"\n        Encode observations corresponding to goals using a list of processors.\n        :param inputs: List of Tensors corresponding to a set of obs.\n        \"\"\"\n        encodes = []\n        for idx in self._goal_processor_indices:\n            processor = self.processors[idx]\n            if not isinstance(processor, EntityEmbedding):\n                # The input can be encoded without having to process other inputs\n                obs_input = inputs[idx]\n                processed_obs = processor(obs_input)\n                encodes.append(processed_obs)\n            else:\n                raise UnityTrainerException(\n                    \"The one of the goals uses variable length observations. This use \"\n                    \"case is not supported.\"\n                )\n        if len(encodes) != 0:\n            encoded = torch.cat(encodes, dim=1)\n        else:\n            raise UnityTrainerException(\n                \"Trainer was unable to process any of the goals provided as input.\"\n            )\n        return encoded\n\n\nclass NetworkBody(nn.Module):\n    def __init__(\n        self,\n        observation_specs: List[ObservationSpec],\n        network_settings: NetworkSettings,\n        encoded_act_size: int = 0,","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/Unity-Technologies/ml-agents/blob/3ecb446f75d1e7400eb404c562dc005d3164cffc/ml-agents/mlagents/trainers/torch_entities/networks.py#L147-L183","documentation":"get_goal_encoding raises UnityTrainerException when one of the goal sensors is an EntityEmbedding sensor (variable-length observations). Goal encodings must be fixed-size and independently encodable per-processor; entity/variable-length sensors can only be encoded jointly with other inputs in the main network path, so using one as a 'goal' is unsupported.","triggerScenarios":"Configuring a self-play or multi-agent scenario where the 'goal' observations include an EntityEmbedding (EntityChildSensor / variable-length entity observation) processor; get_goal_encoding then hits the isinstance(processor, EntityEmbedding) branch and raises.","commonSituations":"Users setting up cooperative multi-agent (e.g. GridWorld/Soccer) configs who assign the entity sensor as a goal input; copying a config that uses entity observations into one that also defines goals.","solutions":["Remove the EntityEmbedding/variable-length sensor from the goal observation set; use fixed-size vector or visual observations as goals","Combine all inputs into the single observation list instead of splitting into goals, so the entity sensor is handled by the main encoding path","Use a different sensor type (VectorSensor) to convey goal information","Check mlagents version docs for supported goal configurations"],"exampleFix":"// before (config: goal uses entity sensor)\ngoals: entity_sensor\n// after\ngoals: vector_goal_sensor  # fixed-size observation","handlingStrategy":"validation","validationCode":"from mlagents.trainers.torch.entities.encoders import EntityEmbedding\nfor spec in goal_specs:\n    if spec.dimension_property and any(p.name == \"VARIABLE_LENGTH\" for p in spec.dimension_property):\n        raise ValueError(\"Goal observations must be fixed-size\")","typeGuard":"def is_fixed_size_goal(spec) -> bool:\n    return not (spec.shape and spec.shape[-1] == 0 or any('VARIABLE' in p.name for p in (spec.dimension_property or [])))","tryCatchPattern":"try:\n    goal_encoding = network.get_goal_encoding(inputs)\nexcept UnityTrainerException as e:\n    logger.error(f\"Unsupported goal observations: {e}\")\n    goal_encoding = None","preventionTips":["Use only fixed-size vector/visual observations as goals","Do not assign EntityChild/variable-length sensors as goal inputs","Consult the multi-agent sample configs for valid goal setups"],"tags":["python","mlagents","unsupported-feature","entity-embeddings"],"backgroundTag":"variable-length-observation-unsupported","analyzedSha":"3ecb446f75d1e7400eb404c562dc005d3164cffc","analyzedAt":"2026-09-02T16:33:12.832Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}