From 94100e25b12dd92a7460a241e735735c0546a485 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Fau=C3=9Fer?= Date: Thu, 2 Jul 2026 19:24:34 +0200 Subject: [PATCH 1/3] Added configurable agent group name and TCP override --- .../godot_rl_agents/controller/ai_controller_2d.gd | 4 +++- .../godot_rl_agents/controller/ai_controller_3d.gd | 4 +++- addons/godot_rl_agents/sync.gd | 12 ++++++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/addons/godot_rl_agents/controller/ai_controller_2d.gd b/addons/godot_rl_agents/controller/ai_controller_2d.gd index 06d928b..b477d24 100644 --- a/addons/godot_rl_agents/controller/ai_controller_2d.gd +++ b/addons/godot_rl_agents/controller/ai_controller_2d.gd @@ -13,6 +13,8 @@ enum ControlModes { @export var onnx_model_path := "" ## Once the number of steps has passed, the flag 'needs_reset' will be set to 'true' for this instance. @export var reset_after := 1000 +## Group name of this agent (must match the agent group name of one of the sync nodes) +@export var agent_group_name := "AGENT" @export_group("Record expert demos mode options") ## Path where the demos will be saved. The file can later be used for imitation learning. @@ -42,7 +44,7 @@ var _player: Node2D func _ready(): - add_to_group("AGENT") + add_to_group(agent_group_name) func init(player: Node2D): diff --git a/addons/godot_rl_agents/controller/ai_controller_3d.gd b/addons/godot_rl_agents/controller/ai_controller_3d.gd index 61a0529..62952de 100644 --- a/addons/godot_rl_agents/controller/ai_controller_3d.gd +++ b/addons/godot_rl_agents/controller/ai_controller_3d.gd @@ -13,6 +13,8 @@ enum ControlModes { @export var onnx_model_path := "" ## Once the number of steps has passed, the flag 'needs_reset' will be set to 'true' for this instance. @export var reset_after := 1000 +## Group name of this agent (must match the agent group name of one of the sync nodes) +@export var agent_group_name := "AGENT" @export_group("Record expert demos mode options") ## Path where the demos will be saved. The file can later be used for imitation learning. @@ -42,7 +44,7 @@ var _player: Node3D func _ready(): - add_to_group("AGENT") + add_to_group(agent_group_name) func init(player: Node3D): diff --git a/addons/godot_rl_agents/sync.gd b/addons/godot_rl_agents/sync.gd index 8428976..d8aefd7 100644 --- a/addons/godot_rl_agents/sync.gd +++ b/addons/godot_rl_agents/sync.gd @@ -17,6 +17,10 @@ enum ControlModes { @export var onnx_model_path := "" ## Whether the inference will be deterministic (NOTE: Only applies to discrete actions in onnx inference mode) @export var deterministic_inference := true +## Group name of the agents that are associated to this sync node (must match the group name of at least one of the AI-controller nodes) +@export var agent_group_name := "AGENT" +## When not empty then this value overrides the TCP port (only needed for 'Training' control mode) +@export var tcp_port_override : String = "" # Onnx model stored for each requested path var onnx_models: Dictionary @@ -360,7 +364,8 @@ func _set_agent_mode(agent: Node): func _get_agents(): - all_agents = get_tree().get_nodes_in_group("AGENT") + all_agents = get_tree().get_nodes_in_group(agent_group_name) + assert (not all_agents.is_empty(), "No AI-controllers found. Check group name: " + agent_group_name) for agent in all_agents: _set_agent_mode(agent) @@ -479,7 +484,10 @@ func _get_speedup(): func _get_port(): - return args.get("port", DEFAULT_PORT).to_int() + if not tcp_port_override.is_empty(): + return str(tcp_port_override).to_int() + else: + return args.get("port", DEFAULT_PORT).to_int() func _set_seed(): From da18ca9cb8d6ee1980648f5a004fec16ecd9e4e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Fau=C3=9Fer?= Date: Thu, 16 Jul 2026 09:19:57 +0200 Subject: [PATCH 2/3] use policy_name instead of agent_group_name, updated tooltips --- addons/godot_rl_agents/controller/ai_controller_2d.gd | 8 +++----- addons/godot_rl_agents/controller/ai_controller_3d.gd | 8 +++----- addons/godot_rl_agents/sync.gd | 10 ++++++---- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/addons/godot_rl_agents/controller/ai_controller_2d.gd b/addons/godot_rl_agents/controller/ai_controller_2d.gd index b477d24..3badc07 100644 --- a/addons/godot_rl_agents/controller/ai_controller_2d.gd +++ b/addons/godot_rl_agents/controller/ai_controller_2d.gd @@ -13,8 +13,6 @@ enum ControlModes { @export var onnx_model_path := "" ## Once the number of steps has passed, the flag 'needs_reset' will be set to 'true' for this instance. @export var reset_after := 1000 -## Group name of this agent (must match the agent group name of one of the sync nodes) -@export var agent_group_name := "AGENT" @export_group("Record expert demos mode options") ## Path where the demos will be saved. The file can later be used for imitation learning. @@ -28,8 +26,8 @@ enum ControlModes { @export_group("Multi-policy mode options") ## Allows you to set certain agents to use different policies. -## Changing has no effect with default SB3 training. Works with Rllib example. -## Tutorial: https://github.com/edbeeching/godot_rl_agents/blob/main/docs/TRAINING_MULTIPLE_POLICIES.md +## Works with Rllib example (one Python server) and SB3 (one Python server per policy) +## RLlib tutorial: https://github.com/edbeeching/godot_rl_agents/blob/main/docs/TRAINING_MULTIPLE_POLICIES.md @export var policy_name: String = "shared_policy" var onnx_model: ONNXModel @@ -44,7 +42,7 @@ var _player: Node2D func _ready(): - add_to_group(agent_group_name) + add_to_group(policy_name) func init(player: Node2D): diff --git a/addons/godot_rl_agents/controller/ai_controller_3d.gd b/addons/godot_rl_agents/controller/ai_controller_3d.gd index 62952de..8f82391 100644 --- a/addons/godot_rl_agents/controller/ai_controller_3d.gd +++ b/addons/godot_rl_agents/controller/ai_controller_3d.gd @@ -13,8 +13,6 @@ enum ControlModes { @export var onnx_model_path := "" ## Once the number of steps has passed, the flag 'needs_reset' will be set to 'true' for this instance. @export var reset_after := 1000 -## Group name of this agent (must match the agent group name of one of the sync nodes) -@export var agent_group_name := "AGENT" @export_group("Record expert demos mode options") ## Path where the demos will be saved. The file can later be used for imitation learning. @@ -28,8 +26,8 @@ enum ControlModes { @export_group("Multi-policy mode options") ## Allows you to set certain agents to use different policies. -## Changing has no effect with default SB3 training. Works with Rllib example. -## Tutorial: https://github.com/edbeeching/godot_rl_agents/blob/main/docs/TRAINING_MULTIPLE_POLICIES.md +## Works with Rllib example (one Python server) and SB3 (one Python server per policy) +## RLlib tutorial: https://github.com/edbeeching/godot_rl_agents/blob/main/docs/TRAINING_MULTIPLE_POLICIES.md @export var policy_name: String = "shared_policy" var onnx_model: ONNXModel @@ -44,7 +42,7 @@ var _player: Node3D func _ready(): - add_to_group(agent_group_name) + add_to_group(policy_name) func init(player: Node3D): diff --git a/addons/godot_rl_agents/sync.gd b/addons/godot_rl_agents/sync.gd index d8aefd7..0769f8a 100644 --- a/addons/godot_rl_agents/sync.gd +++ b/addons/godot_rl_agents/sync.gd @@ -17,8 +17,10 @@ enum ControlModes { @export var onnx_model_path := "" ## Whether the inference will be deterministic (NOTE: Only applies to discrete actions in onnx inference mode) @export var deterministic_inference := true -## Group name of the agents that are associated to this sync node (must match the group name of at least one of the AI-controller nodes) -@export var agent_group_name := "AGENT" + +@export_group("Multi-server mode options") +## Policy name of the AI-controllers that are assigned to this sync node +@export var policy_name: String = "shared_policy" ## When not empty then this value overrides the TCP port (only needed for 'Training' control mode) @export var tcp_port_override : String = "" @@ -364,8 +366,8 @@ func _set_agent_mode(agent: Node): func _get_agents(): - all_agents = get_tree().get_nodes_in_group(agent_group_name) - assert (not all_agents.is_empty(), "No AI-controllers found. Check group name: " + agent_group_name) + all_agents = get_tree().get_nodes_in_group(policy_name) + assert (not all_agents.is_empty(), "No AI-controllers found. Check group name: " + policy_name) for agent in all_agents: _set_agent_mode(agent) From 56c1a3543e7699c87245fc557d938e8494f97ea5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Fau=C3=9Fer?= Date: Thu, 16 Jul 2026 13:41:22 +0200 Subject: [PATCH 3/3] added port_offset argument --- addons/godot_rl_agents/sync.gd | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/addons/godot_rl_agents/sync.gd b/addons/godot_rl_agents/sync.gd index 0769f8a..cb837be 100644 --- a/addons/godot_rl_agents/sync.gd +++ b/addons/godot_rl_agents/sync.gd @@ -32,6 +32,7 @@ var onnx_models: Dictionary const MAJOR_VERSION := "0" const MINOR_VERSION := "7" const DEFAULT_PORT := "11008" +const DEFAULT_PORT_OFFSET := "0" const DEFAULT_SEED := "1" var stream: StreamPeerTCP = null var connected = false @@ -454,7 +455,7 @@ func connect_to_server(): # "localhost" was not working on windows VM, had to use the IP var ip = "127.0.0.1" - var port = _get_port() + var port = _get_port() + _get_port_offset() var connect = stream.connect_to_host(ip, port) stream.set_no_delay(true) # TODO check if this improves performance or not stream.poll() @@ -492,6 +493,10 @@ func _get_port(): return args.get("port", DEFAULT_PORT).to_int() +func _get_port_offset(): + return args.get("port_offset", DEFAULT_PORT_OFFSET).to_int() + + func _set_seed(): var _seed = args.get("env_seed", DEFAULT_SEED).to_int() seed(_seed)