Search Unity

Does AgentReset() gets called when Max steps from the inspector has been reached?

Discussion in 'ML-Agents' started by Print_Hello_World, Mar 18, 2020.

  1. Print_Hello_World

    Print_Hello_World

    Joined:
    Jan 14, 2020
    Posts:
    12
    Hello, I am a bit confused as to how are the agents and academy are being reset.

    I have two conditions for resetting in the game I'm making using self-play

    1: When all agents in a team are "killed" ie SetActive(false), I wrote a method which cycles through each agent and calls their agent.done() method. This condition works well and the agents are reactivated and moved to the current positions. AgentReset() method in the agent script has a "this.gameobject.setactive(true)" line.

    2: i set the max steps to 500. However, when the max steps are reached, the agents do not reactivate. I tested this by "killing" one member of a team and leaving it there till it has reached its max steps. only those agents which are not deactivated move to the correct positions while the deactivated agents stay deactivated. Furthermore, it turns out that for the deactivated agents, when they have reached max steps, their agent reset methods are not being called at all.

    It is strange that condition 1 works but condition 2 does not when to my understanding when the agent has reached its max step, it calls it's its own reset methods.

    Can someone explain why cant my agents reset when it has reached max steps? thanks!

    here is a snippet of my code:

    This essentially checks condition 1 and resets all agents if it is met. this is not the agent script, its a separate monobehaviour script
    upload_2020-3-18_12-38-16.png

    this is the agent reset method in my agent script

    upload_2020-3-18_12-39-34.png

    I took reference from the soccer example hence some of the syntax and variables look familiar :p
     
    Last edited: Mar 18, 2020
  2. Print_Hello_World

    Print_Hello_World

    Joined:
    Jan 14, 2020
    Posts:
    12
    ok so i managed to solve the issue but including this loop which checks at every fixedupdate() if each agent has reached its max step and if i has reset every agent:

    upload_2020-3-18_14-19-8.png

    not exactly an elegant solution as it keeps checking every frame, any ideas anyone?
     
  3. celion_unity

    celion_unity

    Joined:
    Jun 12, 2019
    Posts:
    289
    (I'm assuming you're on the 0.14.1 release. If not, let me know and I'll find the relevant code).

    This shouldn't be necessary - when the agent is stepped by the Academy, it will make the same check and mark the Agent done which will reset it too: https://github.com/Unity-Technologi...om.unity.ml-agents/Runtime/Agent.cs#L794-L798

    However, if you deactivate an Agent, it will no longer get stepped by the Academy, so its step count won't increase:
    https://github.com/Unity-Technologi...4.1/com.unity.ml-agents/Runtime/Agent.cs#L264
    So maybe that's the cause of the confusion?
     
  4. Print_Hello_World

    Print_Hello_World

    Joined:
    Jan 14, 2020
    Posts:
    12
    Hello, yeah I am on 0.14.1.

    That explains why only the deactivated agents don't get reset after they reach their max step. its because their steps don't increase at all while being deactivated.

    I understand whats going on now, thanks for the explanation and references to the code :D
     
    celion_unity likes this.
  5. celion_unity

    celion_unity

    Joined:
    Jun 12, 2019
    Posts:
    289
    Great, glad I could help!