Search Unity

Question problem with the OnEnvironmentReset delegate

Discussion in 'ML-Agents' started by StewedHarry, Jul 30, 2020.

  1. StewedHarry

    StewedHarry

    Joined:
    Jan 20, 2020
    Posts:
    45
    I am having trouble designing a flexible training set up which would allow for multiple different agents to train, or either of these agents to train alone. At the moment, I have it set up so that the delegate I added to Acedemy.Instance.OnEnvironmentReset is called at the beginning of training. This sets up the environment and spawns the agents. After the initial set up, I then call this method when each episode ends - to reset the environment and the agent positions. Because of this, adding multiple agents to the scene would (I think) cause environment restarting delegate to be called multiple times (by as many times as there are agents scene).

    Is there a way to add a delegate that would be called whenever an episode begins? I am not aware of a mechanism for controlling the environment which is agent-independent, aside from the delegate added to OnEnvironmentReset, but this is only called once at the start of training.
     
  2. celion_unity

    celion_unity

    Joined:
    Jun 12, 2019
    Posts:
    289
    For single agents, you can override the Agent.OnEpisodeBegin() method.

    For groups of agents, there's nothing built-in. You can see an example of how to handle this in our Soccer scene; when a goal is scored, each agent gets rewarded and their episode is ended. The OnEpisodeBegin method is used to actually reset the position of the Agent.
     
  3. StewedHarry

    StewedHarry

    Joined:
    Jan 20, 2020
    Posts:
    45
    The problem I have with my training scenario is that the reset positions of the agents will not be known until an external class has generated the environment and allocated agent positions.

    I am looking for a way to initialise this process without calling it from an agents on episode begin.