class_docstr: A MultiAgentEnv representing a single Unity3D game instance.
  
  For an example on how to use this Env with a running Unity3D editor
  or with a compiled game, see:
  `rllib/examples/unity3d_env_local.py`
  For an example on how to use it inside a Unity game client, which
  connects to an RLlib Policy server, see:
  `rllib/examples/serving/unity3d_[client|server].py`
  
  Supports all Unity3D (MLAgents) examples, multi- or single-agent and
  gets converted automatically into an ExternalMultiAgentEnv, when used
  inside an RLlib PolicyClient for cloud/distributed training of Unity games.
class_docstr_tok: ["A","MultiAgentEnv","representing","a","single","Unity3D","game","instance",".","For","an","example","on","how","to","use","this","Env","with","a","running","Unity3D","editor","or","with","a","compiled","game",",","see",":","`","rllib\/examples\/unity3d_env_local.py","`","For","an","example","on","how","to","use","it","inside","a","Unity","game","client",",","which","connects","to","an","RLlib","Policy","server",",","see",":","`","rllib\/examples\/serving\/unity3d_","[","client|server","]",".py","`","Supports","all","Unity3D","(","MLAgents",")","examples",",","multi-","or","single-agent","and","gets","converted","automatically","into","an","ExternalMultiAgentEnv",",","when","used","inside","an","RLlib","PolicyClient","for","cloud\/distributed","training","of","Unity","games","."]
docstr: Performs one multi-agent step through the game.
  
  Args:
      action_dict: Multi-agent action dict with:
          keys=agent identifier consisting of
          [MLagents behavior name, e.g. "Goalie?team=1"] + "_" +
          [Agent index, a unique MLAgent-assigned index per single agent]
  
  Returns:
      tuple:
          - obs: Multi-agent observation dict.
              Only those observations for which to get new actions are
              returned.
          - rewards: Rewards dict matching `obs`.
          - dones: Done dict with only an __all__ multi-agent entry in
              it. __all__=True, if episode is done for all agents.
          - infos: An (empty) info dict.
docstr_tok: ["Performs","one","multi-agent","step","through","the","game",".","Args",":","action_dict",":","Multi-agent","action","dict","with",":","keys=agent","identifier","consisting","of","[","MLagents","behavior","name",",","e.g",".","``","Goalie","?","team=1","''","]","+","``","_","''","+","[","Agent","index",",","a","unique","MLAgent-assigned","index","per","single","agent","]","Returns",":","tuple",":","-","obs",":","Multi-agent","observation","dict",".","Only","those","observations","for","which","to","get","new","actions","are","returned",".","-","rewards",":","Rewards","dict","matching","`","obs","`",".","-","dones",":","Done","dict","with","only","an","__all__","multi-agent","entry","in","it",".","__all__=True",",","if","episode","is","done","for","all","agents",".","-","infos",":","An","(","empty",")","info","dict","."]
code: def step(
      self, action_dict: MultiAgentDict
  ) -> Tuple[
      MultiAgentDict,
      MultiAgentDict,
      MultiAgentDict,
      MultiAgentDict,
      MultiAgentDict,
  ]:
      """Performs one multi-agent step through the game.
  
      Args:
          action_dict: Multi-agent action dict with:
              keys=agent identifier consisting of
              [MLagents behavior name, e.g. "Goalie?team=1"] + "_" +
              [Agent index, a unique MLAgent-assigned index per single agent]
  
      Returns:
          tuple:
              - obs: Multi-agent observation dict.
                  Only those observations for which to get new actions are
                  returned.
              - rewards: Rewards dict matching `obs`.
              - dones: Done dict with only an __all__ multi-agent entry in
                  it. __all__=True, if episode is done for all agents.
              - infos: An (empty) info dict.
      """
      from mlagents_envs.base_env import ActionTuple
  
      # Set only the required actions (from the DecisionSteps) in Unity3D.
      all_agents = []
      for behavior_name in self.unity_env.behavior_specs:
          # New ML-Agents API: Set all agents actions at the same time
          # via an ActionTuple. Since API v1.4.0.
          if self.api_version[0] > 1 or (
              self.api_version[0] == 1 and self.api_version[1] >= 4
          ):
              actions = []
              for agent_id in self.unity_env.get_steps(behavior_name)[
                  0
              ].agent_id:
                  key = behavior_name + "_{}".format(agent_id)
                  all_agents.append(key)
                  actions.append(action_dict[key])
              if actions:
                  if actions[0].dtype == np.float32:
                      action_tuple = ActionTuple(
                          continuous=np.array(actions)
                      )
                  else:
                      action_tuple = ActionTuple(
                          discrete=np.array(actions)
                      )
                  self.unity_env.set_actions(
                      behavior_name, action_tuple
                  )
          # Old behavior: Do not use an ActionTuple and set each agent's
          # action individually.
          else:
              for agent_id in self.unity_env.get_steps(behavior_name)[
                  0
              ].agent_id_to_index.keys():
                  key = behavior_name + "_{}".format(agent_id)
                  all_agents.append(key)
                  self.unity_env.set_action_for_agent(
                      behavior_name, agent_id, action_dict[key]
                  )
      # Do the step.
      self.unity_env.step()
  
      (
          obs,
          rewards,
          terminateds,
          truncateds,
          infos,
      ) = self._get_step_results()
  
      # Global horizon reached? -> Return __all__ truncated=True, so user
      # can reset. Set all agents' individual `truncated` to True as well.
      self.episode_timesteps += 1
      if self.episode_timesteps > self.episode_horizon:
          return (
              obs,
              rewards,
              terminateds,
              dict(
                  {"__all__": True},
                  **{agent_id: True for agent_id in all_agents},
              ),
              infos,
          )
  
      return obs, rewards, terminateds, truncateds, infos
  
file_path: ray/rllib/env/wrappers/unity3d_env.py
imports: from gymnasium.spaces import Box, MultiDiscrete, Tuple
  import logging
  import numpy
  import random
  import time
  from typing import Callable, Optional, Tuple
  from ray.rllib.env.multi_agent_env import MultiAgentEnv
  from ray.rllib.policy.policy import PolicySpec
  from ray.rllib.utils.annotations import PublicAPI
  from ray.rllib.utils.typing import MultiAgentDict, PolicyID, AgentID
label_desc: Use image node_id 2 for calling the Unity3DEnv obj's underlying member method code with example usage: obj.step(action_dict) and returns: obs,  rewards,  terminateds,  truncateds,  infos, obs,  rewards,  terminateds,  dict,  infos