how do I manually call CollectObservations and AgentAction

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?

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:ml-agents/docs/Learning-Environment-Design-Agents.md at 0.14.0 · Unity-Technologies/ml-agents · GitHub

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().

3 Likes

I have tested successfully, thank you

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?