{"record":{"id":"cd7149cd2c7378c1","repo":"Unity-Technologies/ml-agents","slug":"variable-length-observations-are-not-supported-by","errorCode":null,"errorMessage":"Variable Length Observations are not supported by the trainer","messagePattern":"Variable Length Observations are not supported by the trainer","errorType":"exception","errorClass":"UnityAgentsException","httpStatus":null,"severity":"error","filePath":"com.unity.ml-agents/Runtime/Communicator/GrpcExtensions.cs","lineNumber":452,"sourceCode":"                {\n                    observationProto.CompressedChannelMapping.AddRange(compressionSpec.CompressedChannelMapping);\n                }\n            }\n\n            // Add the dimension properties to the observationProto\n            var dimensionProperties = obsSpec.DimensionProperties;\n            for (int i = 0; i < dimensionProperties.Length; i++)\n            {\n                observationProto.DimensionProperties.Add((int)dimensionProperties[i]);\n            }\n\n            // Checking trainer compatibility with variable length observations\n            if (dimensionProperties == new InplaceArray<DimensionProperty>(DimensionProperty.VariableSize, DimensionProperty.None))\n            {\n                var trainerCanHandleVarLenObs = Academy.Instance.TrainerCapabilities == null || Academy.Instance.TrainerCapabilities.VariableLengthObservation;\n                if (!trainerCanHandleVarLenObs)\n                {\n                    throw new UnityAgentsException(\"Variable Length Observations are not supported by the trainer\");\n                }\n            }\n\n            for (var i = 0; i < shape.Length; i++)\n            {\n                observationProto.Shape.Add(shape[i]);\n            }\n\n            var sensorName = sensor.GetName();\n            if (!string.IsNullOrEmpty(sensorName))\n            {\n                observationProto.Name = sensorName;\n            }\n\n            observationProto.ObservationType = (ObservationTypeProto)obsSpec.ObservationType;\n            return observationProto;\n        }\n","sourceCodeStart":434,"sourceCodeEnd":470,"githubUrl":"https://github.com/Unity-Technologies/ml-agents/blob/3ecb446f75d1e7400eb404c562dc005d3164cffc/com.unity.ml-agents/Runtime/Communicator/GrpcExtensions.cs#L434-L470","documentation":"ML-Agents throws this when an observation's dimension properties indicate variable-size (DimensionProperty.VariableSize) but the connected trainer does not declare VariableLengthObservation support in its capabilities. The trainer and Unity side disagree on supported observation formats, so communication is refused before training starts.","triggerScenarios":"A sensor reports VariableSize dimension properties (e.g. via GetObservationSpec with variable dimension properties) while the connected trainer/Python package has capabilities.VariableLengthObservation == false; TrainerCapabilities is non-null and lacks the flag.","commonSituations":"Version mismatch between the ml-agents Python package and the Unity com.unity.ml-agents package; custom sensors with dynamic shapes (e.g. ragged lists of entities) trained with older trainers that only support fixed-size observations.","solutions":["Use a trainer/Python ml-agents version that supports VariableLengthObservation (upgrade the Python package and match Unity package versions)","Make the sensor emit fixed-size observations (pad/crop to a constant shape) and return fixed DimensionProperty.None properties","Remove the VariableSize dimension property from the sensor's ObservationSpec"],"exampleFix":"// before\nvar spec = ObservationSpec.Vector(DimProperty.VariableSize, DimProperty.None);\n// after\nvar spec = ObservationSpec.Vector(FIXED_SIZE); // pad variable data to fixed size","handlingStrategy":"validation","validationCode":"var caps = Academy.Instance.TrainerCapabilities;\nbool varLenOk = caps == null || caps.VariableLengthObservation;\nbool needsVarLen = sensor.GetObservationSpec().DimensionProperties.Contains(DimensionProperty.VariableSize);\nif (needsVarLen && !varLenOk) throw new InvalidOperationException(\"Trainer cannot handle variable-length observations; pad to fixed size.\");","typeGuard":null,"tryCatchPattern":"try { /* connect trainer / build observation proto */ }\ncatch (UnityAgentsException e) when (e.Message == \"Variable Length Observations are not supported by the trainer\")\n{ Debug.LogError(\"Upgrade the ml-agents Python package or make the sensor fixed-size.\"); }","preventionTips":["Keep com.unity.ml-agents and the Python ml-agents package versions in sync","Pad variable-size sensor data to a fixed shape and declare fixed DimensionProperty.None","Check TrainerCapabilities.VariableLengthObservation before enabling variable-size sensors"],"tags":["unity","ml-agents","trainer-compatibility","observation","version-mismatch"],"backgroundTag":"trainer-capability-mismatch","analyzedSha":"3ecb446f75d1e7400eb404c562dc005d3164cffc","analyzedAt":"2026-09-02T16:33:12.832Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}