From 6b160dbc2add5d1a174c14d990d93e4617e40902 Mon Sep 17 00:00:00 2001 From: vincentpierre Date: Thu, 5 Mar 2020 11:24:16 -0800 Subject: [PATCH 1/3] Messages will be consumed when the side channel registers --- .../Runtime/Communicator/RpcCommunicator.cs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/com.unity.ml-agents/Runtime/Communicator/RpcCommunicator.cs b/com.unity.ml-agents/Runtime/Communicator/RpcCommunicator.cs index 6c0abeb8b9..62b79700b6 100644 --- a/com.unity.ml-agents/Runtime/Communicator/RpcCommunicator.cs +++ b/com.unity.ml-agents/Runtime/Communicator/RpcCommunicator.cs @@ -504,6 +504,19 @@ public void RegisterSideChannel(SideChannel sideChannel) "A side channel with type index {0} is already registered. You cannot register multiple " + "side channels of the same id.", channelId)); } + + for (int i = 0; i< m_CachedMessages.Count; i++) + { + var cachedMessage = m_CachedMessages.Dequeue(); + if (channelId == cachedMessage.ChannelId) + { + sideChannel.OnMessageReceived(cachedMessage.Message); + } + else + { + m_CachedMessages.Enqueue(cachedMessage); + } + } m_SideChannels.Add(channelId, sideChannel); } From 481c14f4ce12ba5b2ce18246b37d03fc6b57d8b3 Mon Sep 17 00:00:00 2001 From: vincentpierre Date: Thu, 5 Mar 2020 12:08:52 -0800 Subject: [PATCH 2/3] addressing the comment --- com.unity.ml-agents/Runtime/Communicator/RpcCommunicator.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/com.unity.ml-agents/Runtime/Communicator/RpcCommunicator.cs b/com.unity.ml-agents/Runtime/Communicator/RpcCommunicator.cs index 62b79700b6..ac58cd3343 100644 --- a/com.unity.ml-agents/Runtime/Communicator/RpcCommunicator.cs +++ b/com.unity.ml-agents/Runtime/Communicator/RpcCommunicator.cs @@ -505,7 +505,8 @@ public void RegisterSideChannel(SideChannel sideChannel) "side channels of the same id.", channelId)); } - for (int i = 0; i< m_CachedMessages.Count; i++) + var numMessages = m_CachedMessages.Count; + for (int i = 0; i< numMessages; i++) { var cachedMessage = m_CachedMessages.Dequeue(); if (channelId == cachedMessage.ChannelId) From 760d4f530703687c001468c0a15d85d51f9c71ac Mon Sep 17 00:00:00 2001 From: Vincent-Pierre BERGES Date: Thu, 5 Mar 2020 12:12:32 -0800 Subject: [PATCH 3/3] Update com.unity.ml-agents/Runtime/Communicator/RpcCommunicator.cs Co-Authored-By: Chris Elion --- com.unity.ml-agents/Runtime/Communicator/RpcCommunicator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/com.unity.ml-agents/Runtime/Communicator/RpcCommunicator.cs b/com.unity.ml-agents/Runtime/Communicator/RpcCommunicator.cs index ac58cd3343..dda3240716 100644 --- a/com.unity.ml-agents/Runtime/Communicator/RpcCommunicator.cs +++ b/com.unity.ml-agents/Runtime/Communicator/RpcCommunicator.cs @@ -506,7 +506,7 @@ public void RegisterSideChannel(SideChannel sideChannel) } var numMessages = m_CachedMessages.Count; - for (int i = 0; i< numMessages; i++) + for (int i = 0; i < numMessages; i++) { var cachedMessage = m_CachedMessages.Dequeue(); if (channelId == cachedMessage.ChannelId)