Skip to content

Commit 3ea84c9

Browse files
author
Ruo-Ping Dong
authored
Add stacking option to VectorSensorComponent (#5376)
1 parent 61be828 commit 3ea84c9

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

com.unity.ml-agents/Editor/VectorSensorComponentEditor.cs

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public override void OnInspectorGUI()
2121
EditorGUILayout.PropertyField(so.FindProperty("m_SensorName"), true);
2222
EditorGUILayout.PropertyField(so.FindProperty("m_ObservationSize"), true);
2323
EditorGUILayout.PropertyField(so.FindProperty("m_ObservationType"), true);
24+
EditorGUILayout.PropertyField(so.FindProperty("m_ObservationStacks"), true);
2425
}
2526
EditorGUI.EndDisabledGroup();
2627

com.unity.ml-agents/Runtime/Sensors/VectorSensorComponent.cs

+19
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,32 @@ public ObservationType ObservationType
4646
set { m_ObservationType = value; }
4747
}
4848

49+
[HideInInspector, SerializeField]
50+
[Range(1, 50)]
51+
[Tooltip("Number of camera frames that will be stacked before being fed to the neural network.")]
52+
int m_ObservationStacks = 1;
53+
54+
/// <summary>
55+
/// Whether to stack previous observations. Using 1 means no previous observations.
56+
/// Note that changing this after the sensor is created has no effect.
57+
/// </summary>
58+
public int ObservationStacks
59+
{
60+
get { return m_ObservationStacks; }
61+
set { m_ObservationStacks = value; }
62+
}
63+
4964
/// <summary>
5065
/// Creates a VectorSensor.
5166
/// </summary>
5267
/// <returns></returns>
5368
public override ISensor[] CreateSensors()
5469
{
5570
m_Sensor = new VectorSensor(m_ObservationSize, m_SensorName, m_ObservationType);
71+
if (ObservationStacks != 1)
72+
{
73+
return new ISensor[] { new StackingSensor(m_Sensor, ObservationStacks) };
74+
}
5675
return new ISensor[] { m_Sensor };
5776
}
5877

0 commit comments

Comments
 (0)