From 97146cca5c037e110f24cf06a117e1daa8f4dd3d Mon Sep 17 00:00:00 2001 From: Viviane Rochon Montplaisir Date: Fri, 7 Aug 2026 17:42:30 -0400 Subject: [PATCH 1/4] Only create new sensors when needed --- com.unity.ml-agents/Editor/BehaviorParametersEditor.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/com.unity.ml-agents/Editor/BehaviorParametersEditor.cs b/com.unity.ml-agents/Editor/BehaviorParametersEditor.cs index 5518ac3db82..ae35e543c19 100644 --- a/com.unity.ml-agents/Editor/BehaviorParametersEditor.cs +++ b/com.unity.ml-agents/Editor/BehaviorParametersEditor.cs @@ -122,8 +122,12 @@ void DisplayFailedModelChecks() { return; } - agent.sensors = new List(); - agent.InitializeSensors(); + + if (!EditorApplication.isPlaying || agent.sensors == null) + { + agent.sensors = new List(); + agent.InitializeSensors(); + } var sensors = agent.sensors.ToArray(); ActuatorComponent[] actuatorComponents; From 25ec22a54acc44dd8ce5b4a70590f4cdab4d28d2 Mon Sep 17 00:00:00 2001 From: Viviane Rochon Montplaisir Date: Mon, 10 Aug 2026 11:52:15 -0400 Subject: [PATCH 2/4] update changelog --- com.unity.ml-agents/CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/com.unity.ml-agents/CHANGELOG.md b/com.unity.ml-agents/CHANGELOG.md index 8a028abaccc..af608358fd2 100755 --- a/com.unity.ml-agents/CHANGELOG.md +++ b/com.unity.ml-agents/CHANGELOG.md @@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). +## [Unreleased] +### Minor Changes +#### com.unity.ml-agents (C#) +- Make `BehaviorParametersEditor` create new sensors only when needed. (#6318, #6323) + ## [4.1.0] - 2026-07-27 ### Major Changes #### ml-agents / ml-agents-envs From 2b32fd1d7dad1e68cc87d075c0de1ab94eca2567 Mon Sep 17 00:00:00 2001 From: Viviane Rochon Montplaisir Date: Mon, 10 Aug 2026 12:19:40 -0400 Subject: [PATCH 3/4] address U-PR's comment --- com.unity.ml-agents/Editor/BehaviorParametersEditor.cs | 2 +- com.unity.ml-agents/Runtime/Agent.cs | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/com.unity.ml-agents/Editor/BehaviorParametersEditor.cs b/com.unity.ml-agents/Editor/BehaviorParametersEditor.cs index ae35e543c19..2bcce7b1afa 100644 --- a/com.unity.ml-agents/Editor/BehaviorParametersEditor.cs +++ b/com.unity.ml-agents/Editor/BehaviorParametersEditor.cs @@ -123,7 +123,7 @@ void DisplayFailedModelChecks() return; } - if (!EditorApplication.isPlaying || agent.sensors == null) + if (!EditorApplication.isPlaying || !agent.Initialized) { agent.sensors = new List(); agent.InitializeSensors(); diff --git a/com.unity.ml-agents/Runtime/Agent.cs b/com.unity.ml-agents/Runtime/Agent.cs index fbec5722ec3..3f3b714666e 100644 --- a/com.unity.ml-agents/Runtime/Agent.cs +++ b/com.unity.ml-agents/Runtime/Agent.cs @@ -312,6 +312,12 @@ internal struct AgentParameters /// Whether or not the Agent has been initialized already bool m_Initialized; + /// + /// Whether the Agent is currently initialized (i.e. has live sensors). + /// Set true by LazyInitialize() and reset to false in OnDisable(). + /// + internal bool Initialized => m_Initialized; + /// /// Set of DemonstrationWriters that the Agent will write its step information to. /// If you use a DemonstrationRecorder component, this will automatically register its DemonstrationWriter. From b95ce1d2d2e4ffb3c6a2d838288c5114bc6d08d5 Mon Sep 17 00:00:00 2001 From: Viviane Rochon Montplaisir Date: Mon, 10 Aug 2026 14:11:30 -0400 Subject: [PATCH 4/4] Revert last commit, it creates other issues --- com.unity.ml-agents/Editor/BehaviorParametersEditor.cs | 2 +- com.unity.ml-agents/Runtime/Agent.cs | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/com.unity.ml-agents/Editor/BehaviorParametersEditor.cs b/com.unity.ml-agents/Editor/BehaviorParametersEditor.cs index 2bcce7b1afa..ae35e543c19 100644 --- a/com.unity.ml-agents/Editor/BehaviorParametersEditor.cs +++ b/com.unity.ml-agents/Editor/BehaviorParametersEditor.cs @@ -123,7 +123,7 @@ void DisplayFailedModelChecks() return; } - if (!EditorApplication.isPlaying || !agent.Initialized) + if (!EditorApplication.isPlaying || agent.sensors == null) { agent.sensors = new List(); agent.InitializeSensors(); diff --git a/com.unity.ml-agents/Runtime/Agent.cs b/com.unity.ml-agents/Runtime/Agent.cs index 3f3b714666e..fbec5722ec3 100644 --- a/com.unity.ml-agents/Runtime/Agent.cs +++ b/com.unity.ml-agents/Runtime/Agent.cs @@ -312,12 +312,6 @@ internal struct AgentParameters /// Whether or not the Agent has been initialized already bool m_Initialized; - /// - /// Whether the Agent is currently initialized (i.e. has live sensors). - /// Set true by LazyInitialize() and reset to false in OnDisable(). - /// - internal bool Initialized => m_Initialized; - /// /// Set of DemonstrationWriters that the Agent will write its step information to. /// If you use a DemonstrationRecorder component, this will automatically register its DemonstrationWriter.