/// <summary> /// Performs a single environment update of the Academy and Agent /// objects within the environment. /// </summary> public void EnvironmentStep() { if (!m_HadFirstReset) { ForcedFullReset(); } AgentPreStep?.Invoke(m_StepCount); m_StepCount += 1; m_TotalStepCount += 1; AgentIncrementStep?.Invoke(); using (TimerStack.Instance.Scoped("AgentSendState")) { AgentSendState?.Invoke(); } using (TimerStack.Instance.Scoped("DecideAction")) { DecideAction?.Invoke(); } // If the communicator is not on, we need to clear the SideChannel sending queue if (!IsCommunicatorOn) { SideChannelsManager.GetSideChannelMessage(); } using (TimerStack.Instance.Scoped("AgentAct")) { AgentAct?.Invoke(); } }
/// <summary> /// Performs a single environment update of the Academy and Agent /// objects within the environment. /// </summary> public void EnvironmentStep() { // Check whether we're already in the middle of a step. // This shouldn't happen generally, but could happen if user code (e.g. CollectObservations) // that is called by EnvironmentStep() also calls EnvironmentStep(). This would result // in an infinite loop and/or stack overflow, so stop it before it happens. if (m_IsStepping) { throw new UnityAgentsException( "Academy.EnvironmentStep() called recursively. " + "This might happen if you call EnvironmentStep() from custom code such as " + "CollectObservations() or OnActionReceived()." ); } m_IsStepping = true; try { if (!m_HadFirstReset) { ForcedFullReset(); } AgentPreStep?.Invoke(m_StepCount); m_StepCount += 1; m_TotalStepCount += 1; AgentIncrementStep?.Invoke(); using (TimerStack.Instance.Scoped("AgentSendState")) { AgentSendState?.Invoke(); } using (TimerStack.Instance.Scoped("DecideAction")) { DecideAction?.Invoke(); } // If the communicator is not on, we need to clear the SideChannel sending queue if (!IsCommunicatorOn) { SideChannelManager.GetSideChannelMessage(); } using (TimerStack.Instance.Scoped("AgentAct")) { AgentAct?.Invoke(); } } finally { // Reset m_IsStepping when we're done (or if an exception occurred). m_IsStepping = false; } }