Skip to content

Commit 7c863f1

Browse files
vincentpierreanupambhatnagar
authored andcommitted
Make the demoRecorder write the experience on reset (#3463)
* Make the demoRecorder write the experience on reset * do nothing if demostore is null * Calling reset data if the action is null
1 parent d17ced0 commit 7c863f1

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

com.unity.ml-agents/Runtime/Agent.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,11 @@ void NotifyAgentDone(bool maxStepReached = false)
278278
// We request a decision so Python knows the Agent is done immediately
279279
m_Brain?.RequestDecision(m_Info, sensors);
280280

281+
if (m_Recorder != null && m_Recorder.record && Application.isEditor)
282+
{
283+
m_Recorder.WriteExperience(m_Info, sensors);
284+
}
285+
281286
UpdateRewardStats();
282287

283288
// The Agent is done, so we give it a new episode Id
@@ -799,16 +804,16 @@ void AgentStep()
799804
if ((m_RequestAction) && (m_Brain != null))
800805
{
801806
m_RequestAction = false;
802-
if (m_Action.vectorActions != null)
803-
{
804-
AgentAction(m_Action.vectorActions);
805-
}
807+
AgentAction(m_Action.vectorActions);
806808
}
807809
}
808810

809811
void DecideAction()
810812
{
811813
m_Action.vectorActions = m_Brain?.DecideAction();
814+
if (m_Action.vectorActions == null){
815+
ResetData();
816+
}
812817
}
813818
}
814819
}

com.unity.ml-agents/Runtime/DemonstrationRecorder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static string SanitizeName(string demoName, int maxNameLength)
7373
/// </summary>
7474
public void WriteExperience(AgentInfo info, List<ISensor> sensors)
7575
{
76-
m_DemoStore.Record(info, sensors);
76+
m_DemoStore?.Record(info, sensors);
7777
}
7878

7979
public void Close()

0 commit comments

Comments
 (0)