Unity-Technologies/ml-agents · error · UnityTrainerException
The one of the goals uses variable length observations. This
Error message
The one of the goals uses variable length observations. This use case is not supported.
What it means
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.
Source
Thrown at ml-agents/mlagents/trainers/torch_entities/networks.py:165
)
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)
encodes.append(processed_obs)
else:
raise UnityTrainerException(
"The one of the goals uses variable length observations. This use "
"case is not supported."
)
if len(encodes) != 0:
encoded = torch.cat(encodes, dim=1)
else:
raise UnityTrainerException(
"Trainer was unable to process any of the goals provided as input."
)
return encoded
class NetworkBody(nn.Module):
def __init__(
self,
observation_specs: List[ObservationSpec],
network_settings: NetworkSettings,
encoded_act_size: int = 0,View on GitHub (pinned to 3ecb446f75)
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
Example fix
// before (config: goal uses entity sensor) goals: entity_sensor // after goals: vector_goal_sensor # fixed-size observation
Defensive patterns
Strategy: validation
Validate before calling
from mlagents.trainers.torch.entities.encoders import EntityEmbedding
for spec in goal_specs:
if spec.dimension_property and any(p.name == "VARIABLE_LENGTH" for p in spec.dimension_property):
raise ValueError("Goal observations must be fixed-size") Type guard
def is_fixed_size_goal(spec) -> bool:
return not (spec.shape and spec.shape[-1] == 0 or any('VARIABLE' in p.name for p in (spec.dimension_property or []))) Try / catch
try:
goal_encoding = network.get_goal_encoding(inputs)
except UnityTrainerException as e:
logger.error(f"Unsupported goal observations: {e}")
goal_encoding = None Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- The trainer was unable to process any of the provided inputs
- Trainer was unable to process any of the goals provided as i
- The schedule {self.schedule} is invalid.
- Visual observation resolution ({width}x{height}) is too smal
- Unsupported Sensor with specs {obs_spec}
AI-assisted analysis of Unity-Technologies/ml-agents@3ecb446f75 (2026-09-02).
Data as JSON: /api/errors/12e0fc866109498e.
Report an issue: GitHub.