Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Resolved set_action_for_agent(behavior_name,agent_id,action) seems working differently from the docs?

Discussion in 'ML-Agents' started by zhi_xin, Mar 27, 2021.

  1. zhi_xin

    zhi_xin

    Joined:
    Nov 24, 2020
    Posts:
    2
    Hi I'm using mlagent-envs(0.22.0) for python control of 20 agents in a custom unity scene. What i want is to set actions of agent one by one according to its own observations every time decisions are requested. (The 20 agent have the same behavior and the action(float) size is 2. ) So I checked the docs and thought set_action_for_agent(,,) fits well.

    Here is my python code of one decison step:
    '''py
    agent_id = decision_steps.agent_id
    action = np.ones(2)
    env.set_action_for_agent(behavior_name, agent_id, action)
    env.step()
    '''

    But errors occurs:
    '''
    mlagents_envs.exception.UnityActionException: The behavior FighterBehavior?team=0 needs an input of dimension (20, 2) for (<number of agents>, <action size>) but received input of dimension (2,)
    '''

    I'm confused with the result because it seems defferent from the docs:

    "
    env.set_action_for_agent(agent_group: str, agent_id: int, action: ActionTuple) Sets the action for a specific Agent in an agent group. agent_group is the name of the group the Agent belongs to and agent_id is the integer identifier of the Agent. action is an ActionTuple as described above.
    "
    which I understand as the atrribute action shape should be for a single agent, in my case is (2,)
     
    Last edited: Mar 27, 2021
  2. zhi_xin

    zhi_xin

    Joined:
    Nov 24, 2020
    Posts:
    2
    Delete 356 line 'action = action_spec._validate_action(action, num_agents, behavior_name)' in environment.py solved the problem: