{"record":{"id":"cde20d75676b824d","repo":"Unity-Technologies/ml-agents","slug":"the-behavior-name-needs-a-continuous-input-of-di","errorCode":null,"errorMessage":"The behavior {name} needs a continuous input of dimension {_expected_shape} for (<number of agents>, <action size>) but received input of dimension {actions.continuous.shape}","messagePattern":"The behavior (.+?) needs a continuous input of dimension (.+?) for \\(<number of agents>, <action size>\\) but received input of dimension (.+?)","errorType":"validation","errorClass":"UnityActionException","httpStatus":null,"severity":"error","filePath":"ml-agents-envs/mlagents_envs/base_env.py","lineNumber":421,"sourceCode":"                        self.discrete_branches[i],  # type: ignore\n                        size=(n_agents),\n                        dtype=np.int32,\n                    )\n                    for i in range(self.discrete_size)\n                ]\n            )\n        return ActionTuple(continuous=_continuous, discrete=_discrete)\n\n    def _validate_action(\n        self, actions: ActionTuple, n_agents: int, name: str\n    ) -> ActionTuple:\n        \"\"\"\n        Validates that action has the correct action dim\n        for the correct number of agents and ensures the type.\n        \"\"\"\n        _expected_shape = (n_agents, self.continuous_size)\n        if actions.continuous.shape != _expected_shape:\n            raise UnityActionException(\n                f\"The behavior {name} needs a continuous input of dimension \"\n                f\"{_expected_shape} for (<number of agents>, <action size>) but \"\n                f\"received input of dimension {actions.continuous.shape}\"\n            )\n        _expected_shape = (n_agents, self.discrete_size)\n        if actions.discrete.shape != _expected_shape:\n            raise UnityActionException(\n                f\"The behavior {name} needs a discrete input of dimension \"\n                f\"{_expected_shape} for (<number of agents>, <action size>) but \"\n                f\"received input of dimension {actions.discrete.shape}\"\n            )\n        return actions\n\n    @staticmethod\n    def create_continuous(continuous_size: int) -> \"ActionSpec\":\n        \"\"\"\n        Creates an ActionSpec that is homogenously continuous\n        \"\"\"","sourceCodeStart":403,"sourceCodeEnd":439,"githubUrl":"https://github.com/Unity-Technologies/ml-agents/blob/3ecb446f75d1e7400eb404c562dc005d3164cffc/ml-agents-envs/mlagents_envs/base_env.py#L403-L439","documentation":"BaseEnv._validate_action checks that ActionArgs.continuous has shape (n_agents, continuous_size) matching the BehaviorSpec declared for the behavior. A mismatch raises UnityActionException. This ensures the array you send via set_actions matches what the Unity environment expects for every deciding agent.","triggerScenarios":"Calling env.set_actions(behavior_name, action) where actions.continuous.shape != (number of deciding agents, spec.continuous_action_size) — e.g. one row per known agent instead of only deciding agents, transposed shape, or wrong action dimension.","commonSituations":"Using policy output sized for all agents in the scene while some were done this step; hardcoding action size instead of reading BehaviorSpec; numpy arrays with an extra/missing dimension (shape (n,) instead of (n, k)).","solutions":["Read the expected dims from behavior_spec: spec.action_spec.continuous_size and len(decision_steps) for n_agents, then reshape with np.reshape / np.atleast_2d.","Slice policy outputs to exactly the deciding agents: use decision_steps.agent_id length for the batch dimension.","Upgrade/align policy and env configs — mismatched action spaces between trainer config and Unity behavior parameters cause persistent shape errors."],"exampleFix":"# before\nenv.set_actions(name, policy.decide(all_agent_obs))  # wrong row count\n# after\nimport numpy as np\ncont = policy.decide(decision_steps.obs)\ncont = np.asarray(cont, dtype=np.float32).reshape(len(decision_steps), spec.action_spec.continuous_size)\nenv.set_actions(name, ActionArgs(continuous=cont))","handlingStrategy":"validation","validationCode":"import numpy as np\nn = len(decision_steps)\ncs = behavior_spec.action_spec.continuous_size\ncont = np.asarray(actions.continuous, dtype=np.float32)\nassert cont.shape == (n, cs), f\"need (n_agents, {cs}), got {cont.shape}\"","typeGuard":null,"tryCatchPattern":"try:\n    env.set_actions(name, ActionArgs(continuous=cont))\nexcept UnityActionException as e:\n    print(e)  # inspect expected vs received shapes and reshape\n    raise","preventionTips":["Derive action size from BehaviorSpec, never hardcode","Batch actions by len(decision_steps), not total agents","np.atleast_2d / reshape before set_actions"],"tags":["python","ml-agents","action-space","shape-mismatch","validation"],"backgroundTag":"shape-mismatch","analyzedSha":"3ecb446f75d1e7400eb404c562dc005d3164cffc","analyzedAt":"2026-09-02T16:33:12.832Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}