File tree Expand file tree Collapse file tree 3 files changed +30
-3
lines changed
UnitySDK/Assets/ML-Agents Expand file tree Collapse file tree 3 files changed +30
-3
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,7 @@ public override void OnInspectorGUI()
3333 EditorGUILayout . PropertyField ( so . FindProperty ( "m_InferenceDevice" ) , true ) ;
3434 EditorGUI . indentLevel -- ;
3535 EditorGUILayout . PropertyField ( so . FindProperty ( "m_BehaviorType" ) ) ;
36+ EditorGUILayout . PropertyField ( so . FindProperty ( "m_useChildSensors" ) , true ) ;
3637 // EditorGUILayout.PropertyField(serializedObject.FindProperty("m_Heuristic"), true);
3738 EditorGUI . indentLevel -- ;
3839 if ( EditorGUI . EndChangeCheck ( ) )
@@ -58,7 +59,15 @@ void DisplayFailedModelChecks()
5859 Model barracudaModel = null ;
5960 var model = ( NNModel ) serializedObject . FindProperty ( "m_Model" ) . objectReferenceValue ;
6061 var behaviorParameters = ( BehaviorParameters ) target ;
61- var sensorComponents = behaviorParameters . GetComponents < SensorComponent > ( ) ;
62+ SensorComponent [ ] sensorComponents ;
63+ if ( behaviorParameters . useChildSensors )
64+ {
65+ sensorComponents = behaviorParameters . GetComponentsInChildren < SensorComponent > ( ) ;
66+ }
67+ else
68+ {
69+ sensorComponents = behaviorParameters . GetComponents < SensorComponent > ( ) ;
70+ }
6271 var brainParameters = behaviorParameters . brainParameters ;
6372 if ( model != null )
6473 {
Original file line number Diff line number Diff line change @@ -496,7 +496,16 @@ public virtual float[] Heuristic()
496496 public void InitializeSensors ( )
497497 {
498498 // Get all attached sensor components
499- var attachedSensorComponents = GetComponents < SensorComponent > ( ) ;
499+ SensorComponent [ ] attachedSensorComponents ;
500+ if ( m_PolicyFactory . useChildSensors )
501+ {
502+ attachedSensorComponents = GetComponentsInChildren < SensorComponent > ( ) ;
503+ }
504+ else
505+ {
506+ attachedSensorComponents = GetComponents < SensorComponent > ( ) ;
507+ }
508+
500509 sensors . Capacity += attachedSensorComponents . Length ;
501510 foreach ( var component in attachedSensorComponents )
502511 {
Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ namespace MLAgents
66{
77
88 /// <summary>
9- /// The Factory to generate policies.
9+ /// The Factory to generate policies.
1010 /// </summary>
1111 public class BehaviorParameters : MonoBehaviour
1212 {
@@ -34,12 +34,21 @@ private enum BehaviorType
3434 [ HideInInspector ]
3535 [ SerializeField ]
3636 string m_BehaviorName = "My Behavior" ;
37+ [ HideInInspector ]
38+ [ SerializeField ]
39+ [ Tooltip ( "Use all Sensor components attached to child GameObjects of this Agent." ) ]
40+ bool m_useChildSensors = true ;
3741
3842 public BrainParameters brainParameters
3943 {
4044 get { return m_BrainParameters ; }
4145 }
4246
47+ public bool useChildSensors
48+ {
49+ get { return m_useChildSensors ; }
50+ }
51+
4352 public string behaviorName
4453 {
4554 get { return m_BehaviorName ; }
You can’t perform that action at this time.
0 commit comments