diff --git a/Project/Assets/ML-Agents/Examples/Basic/Scripts/BasicActuatorComponent.cs b/Project/Assets/ML-Agents/Examples/Basic/Scripts/BasicActuatorComponent.cs
index 6369271199..afde4117d8 100644
--- a/Project/Assets/ML-Agents/Examples/Basic/Scripts/BasicActuatorComponent.cs
+++ b/Project/Assets/ML-Agents/Examples/Basic/Scripts/BasicActuatorComponent.cs
@@ -17,7 +17,9 @@ public class BasicActuatorComponent : ActuatorComponent
/// Creates a BasicActuator.
///
///
+#pragma warning disable 672
public override IActuator CreateActuator()
+#pragma warning restore 672
{
return new BasicActuator(basicController);
}
diff --git a/Project/Assets/ML-Agents/Examples/Match3/Scripts/Match3ExampleActuatorComponent.cs b/Project/Assets/ML-Agents/Examples/Match3/Scripts/Match3ExampleActuatorComponent.cs
index 8f32bf1755..7033b35ff3 100644
--- a/Project/Assets/ML-Agents/Examples/Match3/Scripts/Match3ExampleActuatorComponent.cs
+++ b/Project/Assets/ML-Agents/Examples/Match3/Scripts/Match3ExampleActuatorComponent.cs
@@ -7,7 +7,9 @@ namespace Unity.MLAgentsExamples
public class Match3ExampleActuatorComponent : Match3ActuatorComponent
{
///
+#pragma warning disable 672
public override IActuator CreateActuator()
+#pragma warning restore 672
{
var board = GetComponent();
var agent = GetComponentInParent();
diff --git a/com.unity.ml-agents.extensions/Runtime/Match3/Match3ActuatorComponent.cs b/com.unity.ml-agents.extensions/Runtime/Match3/Match3ActuatorComponent.cs
index 7f14fb4ccd..a336b5efbd 100644
--- a/com.unity.ml-agents.extensions/Runtime/Match3/Match3ActuatorComponent.cs
+++ b/com.unity.ml-agents.extensions/Runtime/Match3/Match3ActuatorComponent.cs
@@ -28,7 +28,9 @@ public class Match3ActuatorComponent : ActuatorComponent
public bool ForceHeuristic;
///
+#pragma warning disable 672
public override IActuator CreateActuator()
+#pragma warning restore 672
{
var board = GetComponent();
var agent = GetComponentInParent();
diff --git a/com.unity.ml-agents/CHANGELOG.md b/com.unity.ml-agents/CHANGELOG.md
index a11c60694e..09d6c1916a 100755
--- a/com.unity.ml-agents/CHANGELOG.md
+++ b/com.unity.ml-agents/CHANGELOG.md
@@ -30,6 +30,8 @@ removed when training with a player. The Editor still requires it to be clamped
additional memory allocations. (#4887)
- Added `ObservationWriter.AddList()` and deprecated `ObservationWriter.AddRange()`.
`AddList()` is recommended, as it does not generate any additional memory allocations. (#4887)
+- Added `ActuatorComponent.CreateActuators`, and deprecate `ActuatorComponent.CreateActuator`. The
+ default implementation will wrap `ActuatorComponent.CreateActuator` in an array and return that. (#4899)
#### ml-agents / ml-agents-envs / gym-unity (Python)
- Added a `--torch-device` commandline option to `mlagents-learn`, which sets the default
diff --git a/com.unity.ml-agents/Runtime/Actuators/ActuatorComponent.cs b/com.unity.ml-agents/Runtime/Actuators/ActuatorComponent.cs
index d62fcd7c25..8e0b1814a3 100644
--- a/com.unity.ml-agents/Runtime/Actuators/ActuatorComponent.cs
+++ b/com.unity.ml-agents/Runtime/Actuators/ActuatorComponent.cs
@@ -1,3 +1,4 @@
+using System;
using UnityEngine;
namespace Unity.MLAgents.Actuators
@@ -12,8 +13,21 @@ public abstract class ActuatorComponent : MonoBehaviour
/// Create the IActuator. This is called by the Agent when it is initialized.
///
/// Created IActuator object.
+ [Obsolete("Use CreateActuators instead.")]
public abstract IActuator CreateActuator();
+ ///
+ /// Create a collection of s. This is called by the during
+ /// initialization.
+ ///
+ /// A collection of s
+ public virtual IActuator[] CreateActuators()
+ {
+#pragma warning disable 618
+ return new[] { CreateActuator() };
+#pragma warning restore 618
+ }
+
///
/// The specification of the possible actions for this ActuatorComponent.
/// This must produce the same results as the corresponding IActuator's ActionSpec.
diff --git a/com.unity.ml-agents/Runtime/Actuators/ActuatorManager.cs b/com.unity.ml-agents/Runtime/Actuators/ActuatorManager.cs
index baed948abe..76e9368916 100644
--- a/com.unity.ml-agents/Runtime/Actuators/ActuatorManager.cs
+++ b/com.unity.ml-agents/Runtime/Actuators/ActuatorManager.cs
@@ -369,6 +369,18 @@ void ClearBufferSizes()
NumContinuousActions = NumDiscreteActions = SumOfDiscreteBranchSizes = 0;
}
+ ///
+ /// Add an array of s at once.
+ ///
+ /// The array of s to add.
+ public void AddActuators(IActuator[] actuators)
+ {
+ for (var i = 0; i < actuators.Length; i++)
+ {
+ Add(actuators[i]);
+ }
+ }
+
/*********************************************************************************
* IList implementation that delegates to m_Actuators List. *
*********************************************************************************/
@@ -432,7 +444,7 @@ public bool Remove(IActuator item)
public int Count => m_Actuators.Count;
///
- public bool IsReadOnly => m_Actuators.IsReadOnly;
+ public bool IsReadOnly => false;
///
public int IndexOf(IActuator item)
diff --git a/com.unity.ml-agents/Runtime/Agent.cs b/com.unity.ml-agents/Runtime/Agent.cs
index 29c0dffe73..e1a4191b84 100644
--- a/com.unity.ml-agents/Runtime/Agent.cs
+++ b/com.unity.ml-agents/Runtime/Agent.cs
@@ -1006,7 +1006,7 @@ void InitializeActuators()
foreach (var actuatorComponent in attachedActuators)
{
- m_ActuatorManager.Add(actuatorComponent.CreateActuator());
+ m_ActuatorManager.AddActuators(actuatorComponent.CreateActuators());
}
}
diff --git a/docs/Migrating.md b/docs/Migrating.md
index 0eadcb9f06..e2fa876a40 100644
--- a/docs/Migrating.md
+++ b/docs/Migrating.md
@@ -21,6 +21,15 @@ double-check that the versions are in the same. The versions can be found in
- `VectorSensor.AddObservation(IEnumerable)` is deprecated. Use `VectorSensor.AddObservation(IList)`
instead.
- `ObservationWriter.AddRange()` is deprecated. Use `ObservationWriter.AddList()` instead.
+- `ActuatorComponent.CreateAcuator()` is deprecated. Please use override `ActuatorComponent.CreateActuators`
+ instead. Since `ActuatorComponent.CreateActuator()` is abstract, you will still need to override it in your
+ class until it is removed. It is only ever called if you don't override `ActuatorComponent.CreateActuators`.
+ You can suppress the warnings by surrounding the method with the following pragma:
+ ```c#
+ #pragma warning disable 672
+ public IActuator CreateActuator() { ... }
+ #pragma warning restore 672
+ ```
# Migrating