{"record":{"id":"ff9cbeffd3f4834c","repo":"Unity-Technologies/ml-agents","slug":"action-spaces-with-both-continuous-and-discrete-ac","errorCode":null,"errorMessage":"Action spaces with both continuous and discrete actions are not supported by the trainer. ActionSpecs must be all continuous or all discrete.","messagePattern":"Action spaces with both continuous and discrete actions are not supported by the trainer\\. ActionSpecs must be all continuous or all discrete\\.","errorType":"exception","errorClass":"UnityAgentsException","httpStatus":null,"severity":"error","filePath":"com.unity.ml-agents/Runtime/Actuators/ActionSpec.cs","lineNumber":89,"sourceCode":"        /// <param name=\"numContinuousActions\">The number of continuous actions available.</param>\n        /// <param name=\"discreteBranchSizes\">The array of branch sizes for the discrete actions.  Each index\n        /// contains the number of actions available for that branch.</param>\n        public ActionSpec(int numContinuousActions = 0, int[] discreteBranchSizes = null)\n        {\n            m_NumContinuousActions = numContinuousActions;\n            BranchSizes = discreteBranchSizes ?? Array.Empty<int>();\n        }\n\n        /// <summary>\n        /// Check that the ActionSpec uses either all continuous or all discrete actions.\n        /// This is only used when connecting to old versions of the trainer that don't support this.\n        /// </summary>\n        /// <exception cref=\"UnityAgentsException\"></exception>\n        internal void CheckAllContinuousOrDiscrete()\n        {\n            if (NumContinuousActions > 0 && NumDiscreteActions > 0)\n            {\n                throw new UnityAgentsException(\n                    \"Action spaces with both continuous and discrete actions are not supported by the trainer. \" +\n                    \"ActionSpecs must be all continuous or all discrete.\"\n                );\n            }\n        }\n\n        /// <summary>\n        /// Combines a list of actions specs and allocates a new array of branch sizes if needed.\n        /// </summary>\n        /// <param name=\"specs\">The list of action specs to combine.</param>\n        /// <returns>An ActionSpec which represents the aggregate of the ActionSpecs passed in.</returns>\n        public static ActionSpec Combine(params ActionSpec[] specs)\n        {\n            var numContinuous = 0;\n            var numDiscrete = 0;\n            for (var i = 0; i < specs.Length; i++)\n            {\n                var spec = specs[i];","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/Unity-Technologies/ml-agents/blob/3ecb446f75d1e7400eb404c562dc005d3164cffc/com.unity.ml-agents/Runtime/Actuators/ActionSpec.cs#L71-L107","documentation":"ActionSpec.CheckAllContinuousOrDiscrete throws UnityAgentsException when an action spec declares both NumContinuousActions > 0 and NumDiscreteActions > 0. The ML-Agents trainer only supports action spaces that are entirely continuous or entirely discrete, so hybrid specs are rejected at setup time.","triggerScenarios":"Creating an ActionSpec (or AgentActionBuffer setup) with both continuous and discrete action counts nonzero — typically via mismatched Behavior Parameters or a custom ActionSpec constructor mixing both.","commonSituations":"Configuring Behavior Parameters with a nonzero Continuous Actions count while also adding discrete branches; training configs migrating from older hybrid space attempts.","solutions":["Set either Continuous Actions or the discrete Branch Sizes to zero in Behavior Parameters","Decide the action space type and configure the trainer YAML accordingly (continuous_control vs discrete_control)","Use the Discrete or Continuous-only ActionSpec constructor"],"exampleFix":"// before\nvar spec = new ActionSpec(3, new[] { 2 });\n// after\nvar spec = new ActionSpec(3, null); // all continuous","handlingStrategy":"validation","validationCode":"var spec = new ActionSpec(numContinuous, branches);\nif (spec.NumContinuousActions > 0 && spec.NumDiscreteActions > 0) {\n    Debug.LogError(\"Hybrid action spaces are not supported; pick continuous OR discrete.\");\n}","typeGuard":"bool IsValidActionSpec(ActionSpec s) => s.NumContinuousActions == 0 || s.NumDiscreteActions == 0;","tryCatchPattern":"try { spec.CheckAllContinuousOrDiscrete(); } catch (UnityAgentsException e) { Debug.LogError(e.Message); }","preventionTips":["Set Continuous Actions to 0 for discrete control and vice versa","Match Behavior Parameters with trainer YAML control mode","Never construct ActionSpec with both counts nonzero"],"tags":["unity","ml-agents","action-space","configuration"],"backgroundTag":"invalid-configuration","analyzedSha":"3ecb446f75d1e7400eb404c562dc005d3164cffc","analyzedAt":"2026-09-02T16:33:12.832Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}