Skip to content

Commit b6f72c1

Browse files
The environment can now close right after being instantiated (#4071)
1 parent a997d6c commit b6f72c1

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,8 @@ void InitializeEnvironment()
366366
port = port
367367
}
368368
);
369+
Communicator.QuitCommandReceived += OnQuitCommandReceived;
370+
Communicator.ResetCommandReceived += OnResetCommand;
369371
}
370372

371373
if (Communicator != null)
@@ -397,12 +399,6 @@ void InitializeEnvironment()
397399
);
398400
Communicator = null;
399401
}
400-
401-
if (Communicator != null)
402-
{
403-
Communicator.QuitCommandReceived += OnQuitCommandReceived;
404-
Communicator.ResetCommandReceived += OnResetCommand;
405-
}
406402
}
407403

408404
// If a communicator is enabled/provided, then we assume we are in

com.unity.ml-agents/Runtime/Communicator/RpcCommunicator.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,16 @@ UnityInputProto Initialize(UnityOutputProto unityOutput,
214214

215215
m_Client = new UnityToExternalProto.UnityToExternalProtoClient(channel);
216216
var result = m_Client.Exchange(WrapMessage(unityOutput, 200));
217-
unityInput = m_Client.Exchange(WrapMessage(null, 200)).UnityInput;
217+
var inputMessage = m_Client.Exchange(WrapMessage(null, 200));
218+
unityInput = inputMessage.UnityInput;
218219
#if UNITY_EDITOR
219220
EditorApplication.playModeStateChanged += HandleOnPlayModeChanged;
220221
#endif
222+
if (result.Header.Status != 200 || inputMessage.Header.Status != 200)
223+
{
224+
m_IsOpen = false;
225+
QuitCommandReceived?.Invoke();
226+
}
221227
return result.UnityInput;
222228
#else
223229
throw new UnityAgentsException(

0 commit comments

Comments
 (0)