Skip to content

Commit f6c9c59

Browse files
author
Chris Elion
authored
fix sample code for custom SideChannel (#4466)
* fix sample code for custom SideChannel * update python code too * changelog
1 parent adaad21 commit f6c9c59

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

com.unity.ml-agents/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ your trainer configuration to do so. (#4448)
4040
#### com.unity.ml-agents (C#)
4141
- The package dependencies were updated to include the built-in packages that are used also. (#4384)
4242
#### ml-agents / ml-agents-envs / gym-unity (Python)
43+
- Fixed the sample code in the custom SideChannel example. (#4466)
4344

4445
## [1.3.0-preview] - 2020-08-12
4546

docs/Custom-SideChannels.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public class StringLogSideChannel : SideChannel
8787
ChannelId = new Guid("621f0a70-4f87-11ea-a6bf-784f4387d1f7");
8888
}
8989

90-
public override void OnMessageReceived(IncomingMessage msg)
90+
protected override void OnMessageReceived(IncomingMessage msg)
9191
{
9292
var receivedString = msg.ReadString();
9393
Debug.Log("From Python : " + receivedString);
@@ -209,13 +209,14 @@ env = UnityEnvironment(side_channels=[string_log])
209209
env.reset()
210210
string_log.send_string("The environment was reset")
211211

212-
group_name = env.get_agent_groups()[0] # Get the first group_name
212+
group_name = list(env.behavior_specs.keys())[0] # Get the first group_name
213+
group_spec = env.behavior_specs[group_name]
213214
for i in range(1000):
214-
step_data = env.get_step_result(group_name)
215-
n_agents = step_data.n_agents() # Get the number of agents
215+
decision_steps, terminal_steps = env.get_steps(group_name)
216216
# We send data to Unity : A string with the number of Agent at each
217217
string_log.send_string(
218-
"Step " + str(i) + " occurred with " + str(n_agents) + " agents."
218+
f"Step {i} occurred with {len(decision_steps)} deciding agents and "
219+
f"{len(terminal_steps)} terminal agents"
219220
)
220221
env.step() # Move the simulation forward
221222

0 commit comments

Comments
 (0)