Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

how do I manually call CollectObservations and AgentAction

Discussion in 'ML-Agents' started by xtc002007, Feb 24, 2020.

  1. xtc002007

    xtc002007

    Joined:
    Feb 14, 2018
    Posts:
    3
    hi, currently, when I add DecisionRequester script and call CollectObservations and AgentAction, they are called according to the frequency of FixedUpdate (). If I make a Turn-Based Strategy game, I want to be able to send CollectObservations and get AgentAction only after I press the button. Is this possible? What should I do?
     
  2. celion_unity

    celion_unity

    Joined:
    Jun 12, 2019
    Posts:
    289
    Hi,
    If you call Agent.RequestDecision(), the Agent will call CollectObservations and AgentAction the next time that the Academy is stepped. There's more information here:https://github.com/Unity-Technologi...arning-Environment-Design-Agents.md#decisions

    Starting in 0.14.0, the Academy is a singleton instead of a MonoBehaviour. By default, it will step every FixedUpdate, but you can change this with Academy.Instance.DisableAutomaticStepping() and then call Academy.Instance.EnvironmentStep() when you want the step to happen.

    So putting it all together, for a turn-based game, you would probably call DisableAutomaticStepping() when you're setting things up. When it's time for the AI to take a turn, call Agent.RequestDecision() then Academy.Instance.EnvironmentStep().
     
    idea_Lei likes this.
  3. xtc002007

    xtc002007

    Joined:
    Feb 14, 2018
    Posts:
    3
    I have tested successfully, thank you
     
  4. MattWild888

    MattWild888

    Joined:
    Oct 19, 2022
    Posts:
    13
    I'm using Unity 2021.3.15f1, ML Agents 2.0.1

    I'm finding an issue with Academy steps themselves. Academy steps are not calling the Collect Observations method, and requesting a decision seemingly calls Collect Observations twice. A simple way I tested this was to take away the decision requester; Collect Observations was no longer being called.

    This issue has made it impossible for me to use stacked vectors unless I simply increase the space and do it all manually, as Collect Observations is only called when a decision is requested (and then called again after a decision has been made?).

    Has anyone else encountered this issue?