Unity-Technologies/ml-agents · error · UnityAgentsException

Action spaces with both continuous and discrete actions are

Error message

Action spaces with both continuous and discrete actions are not supported by the trainer. ActionSpecs must be all continuous or all discrete.

What it means

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.

Source

Thrown at com.unity.ml-agents/Runtime/Actuators/ActionSpec.cs:89

        /// <param name="numContinuousActions">The number of continuous actions available.</param>
        /// <param name="discreteBranchSizes">The array of branch sizes for the discrete actions.  Each index
        /// contains the number of actions available for that branch.</param>
        public ActionSpec(int numContinuousActions = 0, int[] discreteBranchSizes = null)
        {
            m_NumContinuousActions = numContinuousActions;
            BranchSizes = discreteBranchSizes ?? Array.Empty<int>();
        }

        /// <summary>
        /// Check that the ActionSpec uses either all continuous or all discrete actions.
        /// This is only used when connecting to old versions of the trainer that don't support this.
        /// </summary>
        /// <exception cref="UnityAgentsException"></exception>
        internal void CheckAllContinuousOrDiscrete()
        {
            if (NumContinuousActions > 0 && NumDiscreteActions > 0)
            {
                throw new UnityAgentsException(
                    "Action spaces with both continuous and discrete actions are not supported by the trainer. " +
                    "ActionSpecs must be all continuous or all discrete."
                );
            }
        }

        /// <summary>
        /// Combines a list of actions specs and allocates a new array of branch sizes if needed.
        /// </summary>
        /// <param name="specs">The list of action specs to combine.</param>
        /// <returns>An ActionSpec which represents the aggregate of the ActionSpecs passed in.</returns>
        public static ActionSpec Combine(params ActionSpec[] specs)
        {
            var numContinuous = 0;
            var numDiscrete = 0;
            for (var i = 0; i < specs.Length; i++)
            {
                var spec = specs[i];

View on GitHub (pinned to 3ecb446f75)

Solutions

  1. Set either Continuous Actions or the discrete Branch Sizes to zero in Behavior Parameters
  2. Decide the action space type and configure the trainer YAML accordingly (continuous_control vs discrete_control)
  3. Use the Discrete or Continuous-only ActionSpec constructor

Example fix

// before
var spec = new ActionSpec(3, new[] { 2 });
// after
var spec = new ActionSpec(3, null); // all continuous
Defensive patterns

Strategy: validation

Validate before calling

var spec = new ActionSpec(numContinuous, branches);
if (spec.NumContinuousActions > 0 && spec.NumDiscreteActions > 0) {
    Debug.LogError("Hybrid action spaces are not supported; pick continuous OR discrete.");
}

Type guard

bool IsValidActionSpec(ActionSpec s) => s.NumContinuousActions == 0 || s.NumDiscreteActions == 0;

Try / catch

try { spec.CheckAllContinuousOrDiscrete(); } catch (UnityAgentsException e) { Debug.LogError(e.Message); }

Prevention

When it happens

Trigger: 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.

Common situations: Configuring Behavior Parameters with a nonzero Continuous Actions count while also adding discrete branches; training configs migrating from older hybrid space attempts.

Related errors


AI-assisted analysis of Unity-Technologies/ml-agents@3ecb446f75 (2026-09-02). Data as JSON: /api/errors/ff9cbeffd3f4834c. Report an issue: GitHub.