From b2c05834354f810dbd949a84ac846611a777ee57 Mon Sep 17 00:00:00 2001 From: Ruo-Ping Dong Date: Tue, 20 Apr 2021 15:11:24 -0700 Subject: [PATCH 1/8] bring back root reference --- .../Prefabs/PushBlockCollabAreaGrid.prefab | 39 +++++++++++++++++-- .../Editor/GridSensorComponentEditor.cs | 1 + .../Runtime/Sensors/GridSensorComponent.cs | 13 ++++++- 3 files changed, 49 insertions(+), 4 deletions(-) diff --git a/Project/Assets/ML-Agents/Examples/PushBlock/Prefabs/PushBlockCollabAreaGrid.prefab b/Project/Assets/ML-Agents/Examples/PushBlock/Prefabs/PushBlockCollabAreaGrid.prefab index c0bbee555e0..3bf4390ad15 100644 --- a/Project/Assets/ML-Agents/Examples/PushBlock/Prefabs/PushBlockCollabAreaGrid.prefab +++ b/Project/Assets/ML-Agents/Examples/PushBlock/Prefabs/PushBlockCollabAreaGrid.prefab @@ -2261,6 +2261,11 @@ PrefabInstance: m_Modification: m_TransformParent: {fileID: 8188317207052398481} m_Modifications: + - target: {fileID: 1548337883655231979, guid: ac01d0f42c5e1463e943632a60d99967, + type: 3} + propertyPath: m_RootReference + value: + objectReference: {fileID: 8190299122290044757} - target: {fileID: 2598450485826216109, guid: ac01d0f42c5e1463e943632a60d99967, type: 3} propertyPath: m_Model @@ -2336,7 +2341,7 @@ MonoBehaviour: type: 3} m_PrefabInstance: {fileID: 6067781793364901444} m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 0} + m_GameObject: {fileID: 8190299122290044757} m_Enabled: 1 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: d94a85eca2e074578943301959c555ba, type: 3} @@ -2348,6 +2353,12 @@ Transform: type: 3} m_PrefabInstance: {fileID: 6067781793364901444} m_PrefabAsset: {fileID: 0} +--- !u!1 &8190299122290044757 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 2710286047221272849, guid: ac01d0f42c5e1463e943632a60d99967, + type: 3} + m_PrefabInstance: {fileID: 6067781793364901444} + m_PrefabAsset: {fileID: 0} --- !u!1001 &6565363751102736699 PrefabInstance: m_ObjectHideFlags: 0 @@ -2355,6 +2366,11 @@ PrefabInstance: m_Modification: m_TransformParent: {fileID: 8188317207052398481} m_Modifications: + - target: {fileID: 1548337883655231979, guid: ac01d0f42c5e1463e943632a60d99967, + type: 3} + propertyPath: m_RootReference + value: + objectReference: {fileID: 9115291448867436586} - target: {fileID: 2598450485826216109, guid: ac01d0f42c5e1463e943632a60d99967, type: 3} propertyPath: m_Model @@ -2435,7 +2451,7 @@ MonoBehaviour: type: 3} m_PrefabInstance: {fileID: 6565363751102736699} m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 0} + m_GameObject: {fileID: 9115291448867436586} m_Enabled: 1 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: d94a85eca2e074578943301959c555ba, type: 3} @@ -2447,6 +2463,12 @@ Transform: type: 3} m_PrefabInstance: {fileID: 6565363751102736699} m_PrefabAsset: {fileID: 0} +--- !u!1 &9115291448867436586 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 2710286047221272849, guid: ac01d0f42c5e1463e943632a60d99967, + type: 3} + m_PrefabInstance: {fileID: 6565363751102736699} + m_PrefabAsset: {fileID: 0} --- !u!1001 &6716844123244810954 PrefabInstance: m_ObjectHideFlags: 0 @@ -2454,6 +2476,11 @@ PrefabInstance: m_Modification: m_TransformParent: {fileID: 8188317207052398481} m_Modifications: + - target: {fileID: 1548337883655231979, guid: ac01d0f42c5e1463e943632a60d99967, + type: 3} + propertyPath: m_RootReference + value: + objectReference: {fileID: 8695281997955662811} - target: {fileID: 2598450485826216109, guid: ac01d0f42c5e1463e943632a60d99967, type: 3} propertyPath: m_Model @@ -2534,7 +2561,7 @@ MonoBehaviour: type: 3} m_PrefabInstance: {fileID: 6716844123244810954} m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 0} + m_GameObject: {fileID: 8695281997955662811} m_Enabled: 1 m_EditorHideFlags: 0 m_Script: {fileID: 11500000, guid: d94a85eca2e074578943301959c555ba, type: 3} @@ -2546,3 +2573,9 @@ Transform: type: 3} m_PrefabInstance: {fileID: 6716844123244810954} m_PrefabAsset: {fileID: 0} +--- !u!1 &8695281997955662811 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 2710286047221272849, guid: ac01d0f42c5e1463e943632a60d99967, + type: 3} + m_PrefabInstance: {fileID: 6716844123244810954} + m_PrefabAsset: {fileID: 0} diff --git a/com.unity.ml-agents/Editor/GridSensorComponentEditor.cs b/com.unity.ml-agents/Editor/GridSensorComponentEditor.cs index 02e89b4696e..0f8920f7de5 100644 --- a/com.unity.ml-agents/Editor/GridSensorComponentEditor.cs +++ b/com.unity.ml-agents/Editor/GridSensorComponentEditor.cs @@ -35,6 +35,7 @@ public override void OnInspectorGUI() var gridSize2d = new Vector3Int(gridSize.vector3IntValue.x, 1, gridSize.vector3IntValue.z); var newGridSize = EditorGUILayout.Vector3IntField("Grid Size", gridSize2d); gridSize.vector3IntValue = new Vector3Int(newGridSize.x, 1, newGridSize.z); + EditorGUILayout.PropertyField(so.FindProperty(nameof(GridSensorComponent.m_RootReference)), true); } EditorGUI.EndDisabledGroup(); EditorGUILayout.PropertyField(so.FindProperty(nameof(GridSensorComponent.m_RotateWithAgent)), true); diff --git a/com.unity.ml-agents/Runtime/Sensors/GridSensorComponent.cs b/com.unity.ml-agents/Runtime/Sensors/GridSensorComponent.cs index 6cf3628b090..b4a3cd73134 100644 --- a/com.unity.ml-agents/Runtime/Sensors/GridSensorComponent.cs +++ b/com.unity.ml-agents/Runtime/Sensors/GridSensorComponent.cs @@ -72,6 +72,17 @@ public bool RotateWithAgent set { m_RotateWithAgent = value; } } + [HideInInspector, SerializeField] + internal GameObject m_RootReference; + /// + /// Rotate the grid based on the direction the agent is facing. + /// + public GameObject RootReference + { + get { return (m_RootReference == null ? gameObject : m_RootReference); } + set { m_RootReference = value; } + } + [HideInInspector, SerializeField] internal string[] m_DetectableTags; /// @@ -190,7 +201,7 @@ public override ISensor[] CreateSensors() m_GridSize, m_RotateWithAgent, m_ColliderMask, - gameObject, + RootReference, m_DetectableTags, m_InitialColliderBufferSize, m_MaxColliderBufferSize From 9bea51f3644133f5f7cf59d612b539cba8991858 Mon Sep 17 00:00:00 2001 From: Ruo-Ping Dong Date: Tue, 20 Apr 2021 15:18:06 -0700 Subject: [PATCH 2/8] docstring --- com.unity.ml-agents/Editor/GridSensorComponentEditor.cs | 2 +- com.unity.ml-agents/Runtime/Sensors/GridSensorComponent.cs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/com.unity.ml-agents/Editor/GridSensorComponentEditor.cs b/com.unity.ml-agents/Editor/GridSensorComponentEditor.cs index 0f8920f7de5..eb3b80f2ca4 100644 --- a/com.unity.ml-agents/Editor/GridSensorComponentEditor.cs +++ b/com.unity.ml-agents/Editor/GridSensorComponentEditor.cs @@ -35,9 +35,9 @@ public override void OnInspectorGUI() var gridSize2d = new Vector3Int(gridSize.vector3IntValue.x, 1, gridSize.vector3IntValue.z); var newGridSize = EditorGUILayout.Vector3IntField("Grid Size", gridSize2d); gridSize.vector3IntValue = new Vector3Int(newGridSize.x, 1, newGridSize.z); - EditorGUILayout.PropertyField(so.FindProperty(nameof(GridSensorComponent.m_RootReference)), true); } EditorGUI.EndDisabledGroup(); + EditorGUILayout.PropertyField(so.FindProperty(nameof(GridSensorComponent.m_RootReference)), true); EditorGUILayout.PropertyField(so.FindProperty(nameof(GridSensorComponent.m_RotateWithAgent)), true); EditorGUI.BeginDisabledGroup(!EditorUtilities.CanUpdateModelProperties()); diff --git a/com.unity.ml-agents/Runtime/Sensors/GridSensorComponent.cs b/com.unity.ml-agents/Runtime/Sensors/GridSensorComponent.cs index b4a3cd73134..ff9bfb33018 100644 --- a/com.unity.ml-agents/Runtime/Sensors/GridSensorComponent.cs +++ b/com.unity.ml-agents/Runtime/Sensors/GridSensorComponent.cs @@ -75,7 +75,8 @@ public bool RotateWithAgent [HideInInspector, SerializeField] internal GameObject m_RootReference; /// - /// Rotate the grid based on the direction the agent is facing. + /// The reference of the root of the agent. This is used to disambiguate objects with + /// the same tag as the agent. Defaults to current GameObject. /// public GameObject RootReference { From dd3182a4dc50adc4ed0a2ae57bcce5e9d2adb0d8 Mon Sep 17 00:00:00 2001 From: Ruo-Ping Dong Date: Tue, 20 Apr 2021 15:42:44 -0700 Subject: [PATCH 3/8] center the sensor around game object not root --- .../Runtime/Sensors/BoxOverlapChecker.cs | 11 +++++++---- .../Runtime/Sensors/GridSensorComponent.cs | 1 + .../Tests/Runtime/Sensor/BoxOverlapCheckerTests.cs | 4 ++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/com.unity.ml-agents/Runtime/Sensors/BoxOverlapChecker.cs b/com.unity.ml-agents/Runtime/Sensors/BoxOverlapChecker.cs index 93029722b2d..05ec26deb30 100644 --- a/com.unity.ml-agents/Runtime/Sensors/BoxOverlapChecker.cs +++ b/com.unity.ml-agents/Runtime/Sensors/BoxOverlapChecker.cs @@ -9,6 +9,7 @@ internal class BoxOverlapChecker Vector3Int m_GridSize; bool m_RotateWithAgent; LayerMask m_ColliderMask; + GameObject m_CenterObject; GameObject m_RootReference; string[] m_DetectableTags; int m_InitialColliderBufferSize; @@ -32,6 +33,7 @@ public BoxOverlapChecker( Vector3Int gridSize, bool rotateWithAgent, LayerMask colliderMask, + GameObject centerObject, GameObject rootReference, string[] detectableTags, int initialColliderBufferSize, @@ -41,6 +43,7 @@ public BoxOverlapChecker( m_GridSize = gridSize; m_RotateWithAgent = rotateWithAgent; m_ColliderMask = colliderMask; + m_CenterObject = centerObject; m_RootReference = rootReference; m_DetectableTags = detectableTags; m_InitialColliderBufferSize = initialColliderBufferSize; @@ -95,17 +98,17 @@ internal Vector3 GetCellGlobalPosition(int cellIndex) { if (m_RotateWithAgent) { - return m_RootReference.transform.TransformPoint(m_CellLocalPositions[cellIndex]); + return m_CenterObject.transform.TransformPoint(m_CellLocalPositions[cellIndex]); } else { - return m_CellLocalPositions[cellIndex] + m_RootReference.transform.position; + return m_CellLocalPositions[cellIndex] + m_CenterObject.transform.position; } } internal Quaternion GetGridRotation() { - return m_RotateWithAgent ? m_RootReference.transform.rotation : Quaternion.identity; + return m_RotateWithAgent ? m_CenterObject.transform.rotation : Quaternion.identity; } /// @@ -197,7 +200,7 @@ void ParseCollidersClosest(Collider[] foundColliders, int numFound, int cellInde } var closestColliderPoint = foundColliders[i].ClosestPointOnBounds(cellCenter); - var currentDistanceSquared = (closestColliderPoint - m_RootReference.transform.position).sqrMagnitude; + var currentDistanceSquared = (closestColliderPoint - m_CenterObject.transform.position).sqrMagnitude; if (currentDistanceSquared >= minDistanceSquared) { diff --git a/com.unity.ml-agents/Runtime/Sensors/GridSensorComponent.cs b/com.unity.ml-agents/Runtime/Sensors/GridSensorComponent.cs index ff9bfb33018..00814ff783d 100644 --- a/com.unity.ml-agents/Runtime/Sensors/GridSensorComponent.cs +++ b/com.unity.ml-agents/Runtime/Sensors/GridSensorComponent.cs @@ -202,6 +202,7 @@ public override ISensor[] CreateSensors() m_GridSize, m_RotateWithAgent, m_ColliderMask, + gameObject, RootReference, m_DetectableTags, m_InitialColliderBufferSize, diff --git a/com.unity.ml-agents/Tests/Runtime/Sensor/BoxOverlapCheckerTests.cs b/com.unity.ml-agents/Tests/Runtime/Sensor/BoxOverlapCheckerTests.cs index 78844144349..1871c69cffd 100644 --- a/com.unity.ml-agents/Tests/Runtime/Sensor/BoxOverlapCheckerTests.cs +++ b/com.unity.ml-agents/Tests/Runtime/Sensor/BoxOverlapCheckerTests.cs @@ -14,6 +14,7 @@ public TestBoxOverlapChecker( Vector3Int gridSize, bool rotateWithAgent, LayerMask colliderMask, + GameObject centerObject, GameObject rootReference, string[] detectableTags, int initialColliderBufferSize, @@ -23,6 +24,7 @@ int maxColliderBufferSize gridSize, rotateWithAgent, colliderMask, + centerObject, rootReference, detectableTags, initialColliderBufferSize, @@ -53,6 +55,7 @@ public static TestBoxOverlapChecker CreateChecker( int gridSizeX = 10, int gridSizeZ = 10, bool rotateWithAgent = true, + GameObject centerObject = null, GameObject rootReference = null, string[] detectableTags = null, int initialColliderBufferSize = 4, @@ -63,6 +66,7 @@ public static TestBoxOverlapChecker CreateChecker( new Vector3Int(gridSizeX, 1, gridSizeZ), rotateWithAgent, LayerMask.GetMask("Default"), + centerObject, rootReference, detectableTags, initialColliderBufferSize, From 7b568ea5ae2dc566753550f58813d6d251ecb781 Mon Sep 17 00:00:00 2001 From: Ruo-Ping Dong Date: Tue, 20 Apr 2021 15:51:42 -0700 Subject: [PATCH 4/8] fix tests --- .../Tests/Runtime/Sensor/BoxOverlapCheckerTests.cs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/com.unity.ml-agents/Tests/Runtime/Sensor/BoxOverlapCheckerTests.cs b/com.unity.ml-agents/Tests/Runtime/Sensor/BoxOverlapCheckerTests.cs index 1871c69cffd..1616380c43f 100644 --- a/com.unity.ml-agents/Tests/Runtime/Sensor/BoxOverlapCheckerTests.cs +++ b/com.unity.ml-agents/Tests/Runtime/Sensor/BoxOverlapCheckerTests.cs @@ -108,7 +108,7 @@ public void TestCellGlobalPositionNoRotate() var testGo = new GameObject("test"); var position = new Vector3(3.5f, 8f, 17f); testGo.transform.position = position; - var boxOverlap = TestBoxOverlapChecker.CreateChecker(gridSizeX: 10, gridSizeZ: 10, rotateWithAgent: false, rootReference: testGo); + var boxOverlap = TestBoxOverlapChecker.CreateChecker(gridSizeX: 10, gridSizeZ: 10, rotateWithAgent: false, rootReference: testGo, centerObject: testGo); Assert.AreEqual(new Vector3(-4.5f, 0, -4.5f) + position, boxOverlap.GetCellGlobalPosition(0)); Assert.AreEqual(new Vector3(-4.5f, 0, 4.5f) + position, boxOverlap.GetCellGlobalPosition(9)); @@ -130,7 +130,7 @@ public void TestCellGlobalPositionRotate() var testGo = new GameObject("test"); var position = new Vector3(15f, 6f, 13f); testGo.transform.position = position; - var boxOverlap = TestBoxOverlapChecker.CreateChecker(gridSizeX: 5, gridSizeZ: 15, rotateWithAgent: true, rootReference: testGo); + var boxOverlap = TestBoxOverlapChecker.CreateChecker(gridSizeX: 5, gridSizeZ: 15, rotateWithAgent: true, rootReference: testGo, centerObject: testGo); Assert.AreEqual(new Vector3(-2f, 0, -7f) + position, boxOverlap.GetCellGlobalPosition(0)); Assert.AreEqual(new Vector3(-2f, 0, 7f) + position, boxOverlap.GetCellGlobalPosition(14)); @@ -154,7 +154,7 @@ public void TestBufferResize() var testGo = new GameObject("test"); testGo.transform.position = Vector3.zero; testObjects.Add(testGo); - var boxOverlap = TestBoxOverlapChecker.CreateChecker(rootReference: testGo, initialColliderBufferSize: 2, maxColliderBufferSize: 5); + var boxOverlap = TestBoxOverlapChecker.CreateChecker(rootReference: testGo, centerObject: testGo, initialColliderBufferSize: 2, maxColliderBufferSize: 5); boxOverlap.Update(); Assert.AreEqual(2, boxOverlap.ColliderBuffer.Length); @@ -198,6 +198,7 @@ public void TestParseCollidersClosest() gridSizeX: 2, gridSizeZ: 2, rootReference: testGo, + centerObject: testGo, detectableTags: new [] { tag1 }); var helper = new VerifyParseCollidersHelper(); boxOverlap.GridOverlapDetectedClosest += helper.DetectedAction; @@ -234,6 +235,7 @@ public void TestParseCollidersAll() gridSizeX: 2, gridSizeZ: 2, rootReference: testGo, + centerObject: testGo, detectableTags: new [] { tag1 }); var helper = new VerifyParseCollidersHelper(); boxOverlap.GridOverlapDetectedAll += helper.DetectedAction; From 240e136fd7e504d5f1b71717f023aad5e1fb63f1 Mon Sep 17 00:00:00 2001 From: Ruo-Ping Dong Date: Thu, 22 Apr 2021 09:53:26 -0700 Subject: [PATCH 5/8] rename root reference to agent game object --- .../Examples/PushBlock/Scenes/PushBlockCollab.unity | 5 +++++ .../Editor/GridSensorComponentEditor.cs | 2 +- .../Runtime/Sensors/GridSensorComponent.cs | 10 +++++----- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Project/Assets/ML-Agents/Examples/PushBlock/Scenes/PushBlockCollab.unity b/Project/Assets/ML-Agents/Examples/PushBlock/Scenes/PushBlockCollab.unity index f6a12a0448d..7450774ee44 100644 --- a/Project/Assets/ML-Agents/Examples/PushBlock/Scenes/PushBlockCollab.unity +++ b/Project/Assets/ML-Agents/Examples/PushBlock/Scenes/PushBlockCollab.unity @@ -816,6 +816,11 @@ PrefabInstance: m_Modification: m_TransformParent: {fileID: 0} m_Modifications: + - target: {fileID: 4704531522807670703, guid: f5bbed44a6ea747a687fbbb738eb1730, + type: 3} + propertyPath: m_ShowGizmos + value: 0 + objectReference: {fileID: 0} - target: {fileID: 8188317207052398481, guid: f5bbed44a6ea747a687fbbb738eb1730, type: 3} propertyPath: m_RootOrder diff --git a/com.unity.ml-agents/Editor/GridSensorComponentEditor.cs b/com.unity.ml-agents/Editor/GridSensorComponentEditor.cs index eb3b80f2ca4..fa9208e274b 100644 --- a/com.unity.ml-agents/Editor/GridSensorComponentEditor.cs +++ b/com.unity.ml-agents/Editor/GridSensorComponentEditor.cs @@ -37,7 +37,7 @@ public override void OnInspectorGUI() gridSize.vector3IntValue = new Vector3Int(newGridSize.x, 1, newGridSize.z); } EditorGUI.EndDisabledGroup(); - EditorGUILayout.PropertyField(so.FindProperty(nameof(GridSensorComponent.m_RootReference)), true); + EditorGUILayout.PropertyField(so.FindProperty(nameof(GridSensorComponent.m_AgentGameObject)), true); EditorGUILayout.PropertyField(so.FindProperty(nameof(GridSensorComponent.m_RotateWithAgent)), true); EditorGUI.BeginDisabledGroup(!EditorUtilities.CanUpdateModelProperties()); diff --git a/com.unity.ml-agents/Runtime/Sensors/GridSensorComponent.cs b/com.unity.ml-agents/Runtime/Sensors/GridSensorComponent.cs index 00814ff783d..6efe32c66ed 100644 --- a/com.unity.ml-agents/Runtime/Sensors/GridSensorComponent.cs +++ b/com.unity.ml-agents/Runtime/Sensors/GridSensorComponent.cs @@ -73,15 +73,15 @@ public bool RotateWithAgent } [HideInInspector, SerializeField] - internal GameObject m_RootReference; + internal GameObject m_AgentGameObject; /// /// The reference of the root of the agent. This is used to disambiguate objects with /// the same tag as the agent. Defaults to current GameObject. /// - public GameObject RootReference + public GameObject AgentGameObject { - get { return (m_RootReference == null ? gameObject : m_RootReference); } - set { m_RootReference = value; } + get { return (m_AgentGameObject == null ? gameObject : m_AgentGameObject); } + set { m_AgentGameObject = value; } } [HideInInspector, SerializeField] @@ -203,7 +203,7 @@ public override ISensor[] CreateSensors() m_RotateWithAgent, m_ColliderMask, gameObject, - RootReference, + AgentGameObject, m_DetectableTags, m_InitialColliderBufferSize, m_MaxColliderBufferSize From 72124b0f2a227e495e017454595ff2dd70479caf Mon Sep 17 00:00:00 2001 From: Ruo-Ping Dong Date: Thu, 22 Apr 2021 09:56:30 -0700 Subject: [PATCH 6/8] update scene --- .../Prefabs/PushBlockCollabAreaGrid.prefab | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/Project/Assets/ML-Agents/Examples/PushBlock/Prefabs/PushBlockCollabAreaGrid.prefab b/Project/Assets/ML-Agents/Examples/PushBlock/Prefabs/PushBlockCollabAreaGrid.prefab index 3bf4390ad15..6f681e1e5ac 100644 --- a/Project/Assets/ML-Agents/Examples/PushBlock/Prefabs/PushBlockCollabAreaGrid.prefab +++ b/Project/Assets/ML-Agents/Examples/PushBlock/Prefabs/PushBlockCollabAreaGrid.prefab @@ -2266,6 +2266,11 @@ PrefabInstance: propertyPath: m_RootReference value: objectReference: {fileID: 8190299122290044757} + - target: {fileID: 1548337883655231979, guid: ac01d0f42c5e1463e943632a60d99967, + type: 3} + propertyPath: m_AgentGameObject + value: + objectReference: {fileID: 8190299122290044757} - target: {fileID: 2598450485826216109, guid: ac01d0f42c5e1463e943632a60d99967, type: 3} propertyPath: m_Model @@ -2371,6 +2376,11 @@ PrefabInstance: propertyPath: m_RootReference value: objectReference: {fileID: 9115291448867436586} + - target: {fileID: 1548337883655231979, guid: ac01d0f42c5e1463e943632a60d99967, + type: 3} + propertyPath: m_AgentGameObject + value: + objectReference: {fileID: 9115291448867436586} - target: {fileID: 2598450485826216109, guid: ac01d0f42c5e1463e943632a60d99967, type: 3} propertyPath: m_Model @@ -2481,6 +2491,11 @@ PrefabInstance: propertyPath: m_RootReference value: objectReference: {fileID: 8695281997955662811} + - target: {fileID: 1548337883655231979, guid: ac01d0f42c5e1463e943632a60d99967, + type: 3} + propertyPath: m_AgentGameObject + value: + objectReference: {fileID: 8695281997955662811} - target: {fileID: 2598450485826216109, guid: ac01d0f42c5e1463e943632a60d99967, type: 3} propertyPath: m_Model From 7f5d9b1a76f0bfa1f62356578503c1f56f0c3a85 Mon Sep 17 00:00:00 2001 From: Ruo-Ping Dong Date: Thu, 22 Apr 2021 10:00:03 -0700 Subject: [PATCH 7/8] also update internal names --- .../Runtime/Sensors/BoxOverlapChecker.cs | 10 ++++----- .../Runtime/Sensor/BoxOverlapCheckerTests.cs | 22 +++++++++---------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/com.unity.ml-agents/Runtime/Sensors/BoxOverlapChecker.cs b/com.unity.ml-agents/Runtime/Sensors/BoxOverlapChecker.cs index 05ec26deb30..f3183975eeb 100644 --- a/com.unity.ml-agents/Runtime/Sensors/BoxOverlapChecker.cs +++ b/com.unity.ml-agents/Runtime/Sensors/BoxOverlapChecker.cs @@ -10,7 +10,7 @@ internal class BoxOverlapChecker bool m_RotateWithAgent; LayerMask m_ColliderMask; GameObject m_CenterObject; - GameObject m_RootReference; + GameObject m_AgentGameObject; string[] m_DetectableTags; int m_InitialColliderBufferSize; int m_MaxColliderBufferSize; @@ -34,7 +34,7 @@ public BoxOverlapChecker( bool rotateWithAgent, LayerMask colliderMask, GameObject centerObject, - GameObject rootReference, + GameObject agentGameObject, string[] detectableTags, int initialColliderBufferSize, int maxColliderBufferSize) @@ -44,7 +44,7 @@ public BoxOverlapChecker( m_RotateWithAgent = rotateWithAgent; m_ColliderMask = colliderMask; m_CenterObject = centerObject; - m_RootReference = rootReference; + m_AgentGameObject = agentGameObject; m_DetectableTags = detectableTags; m_InitialColliderBufferSize = initialColliderBufferSize; m_MaxColliderBufferSize = maxColliderBufferSize; @@ -194,7 +194,7 @@ void ParseCollidersClosest(Collider[] foundColliders, int numFound, int cellInde var currentColliderGo = foundColliders[i].gameObject; // Continue if the current collider go is the root reference - if (ReferenceEquals(currentColliderGo, m_RootReference)) + if (ReferenceEquals(currentColliderGo, m_AgentGameObject)) { continue; } @@ -238,7 +238,7 @@ void ParseCollidersAll(Collider[] foundColliders, int numFound, int cellIndex, V for (int i = 0; i < numFound; i++) { var currentColliderGo = foundColliders[i].gameObject; - if (!ReferenceEquals(currentColliderGo, m_RootReference)) + if (!ReferenceEquals(currentColliderGo, m_AgentGameObject)) { detectedAction.Invoke(currentColliderGo, cellIndex); } diff --git a/com.unity.ml-agents/Tests/Runtime/Sensor/BoxOverlapCheckerTests.cs b/com.unity.ml-agents/Tests/Runtime/Sensor/BoxOverlapCheckerTests.cs index 1616380c43f..2c00494f1ee 100644 --- a/com.unity.ml-agents/Tests/Runtime/Sensor/BoxOverlapCheckerTests.cs +++ b/com.unity.ml-agents/Tests/Runtime/Sensor/BoxOverlapCheckerTests.cs @@ -15,7 +15,7 @@ public TestBoxOverlapChecker( bool rotateWithAgent, LayerMask colliderMask, GameObject centerObject, - GameObject rootReference, + GameObject agentGameObject, string[] detectableTags, int initialColliderBufferSize, int maxColliderBufferSize @@ -25,7 +25,7 @@ int maxColliderBufferSize rotateWithAgent, colliderMask, centerObject, - rootReference, + agentGameObject, detectableTags, initialColliderBufferSize, maxColliderBufferSize) @@ -56,7 +56,7 @@ public static TestBoxOverlapChecker CreateChecker( int gridSizeZ = 10, bool rotateWithAgent = true, GameObject centerObject = null, - GameObject rootReference = null, + GameObject agentGameObject = null, string[] detectableTags = null, int initialColliderBufferSize = 4, int maxColliderBufferSize = 500) @@ -67,7 +67,7 @@ public static TestBoxOverlapChecker CreateChecker( rotateWithAgent, LayerMask.GetMask("Default"), centerObject, - rootReference, + agentGameObject, detectableTags, initialColliderBufferSize, maxColliderBufferSize); @@ -81,7 +81,7 @@ public void TestCellLocalPosition() { var testGo = new GameObject("test"); testGo.transform.position = Vector3.zero; - var boxOverlapSquare = TestBoxOverlapChecker.CreateChecker(gridSizeX: 10, gridSizeZ: 10, rotateWithAgent: false, rootReference: testGo); + var boxOverlapSquare = TestBoxOverlapChecker.CreateChecker(gridSizeX: 10, gridSizeZ: 10, rotateWithAgent: false, agentGameObject: testGo); var localPos = boxOverlapSquare.CellLocalPositions; Assert.AreEqual(new Vector3(-4.5f, 0, -4.5f), localPos[0]); @@ -92,7 +92,7 @@ public void TestCellLocalPosition() var testGo2 = new GameObject("test"); testGo2.transform.position = new Vector3(3.5f, 8f, 17f); // random, should have no effect on local positions - var boxOverlapRect = TestBoxOverlapChecker.CreateChecker(gridSizeX: 5, gridSizeZ: 15, rotateWithAgent: true, rootReference: testGo); + var boxOverlapRect = TestBoxOverlapChecker.CreateChecker(gridSizeX: 5, gridSizeZ: 15, rotateWithAgent: true, agentGameObject: testGo); localPos = boxOverlapRect.CellLocalPositions; Assert.AreEqual(new Vector3(-2f, 0, -7f), localPos[0]); @@ -108,7 +108,7 @@ public void TestCellGlobalPositionNoRotate() var testGo = new GameObject("test"); var position = new Vector3(3.5f, 8f, 17f); testGo.transform.position = position; - var boxOverlap = TestBoxOverlapChecker.CreateChecker(gridSizeX: 10, gridSizeZ: 10, rotateWithAgent: false, rootReference: testGo, centerObject: testGo); + var boxOverlap = TestBoxOverlapChecker.CreateChecker(gridSizeX: 10, gridSizeZ: 10, rotateWithAgent: false, agentGameObject: testGo, centerObject: testGo); Assert.AreEqual(new Vector3(-4.5f, 0, -4.5f) + position, boxOverlap.GetCellGlobalPosition(0)); Assert.AreEqual(new Vector3(-4.5f, 0, 4.5f) + position, boxOverlap.GetCellGlobalPosition(9)); @@ -130,7 +130,7 @@ public void TestCellGlobalPositionRotate() var testGo = new GameObject("test"); var position = new Vector3(15f, 6f, 13f); testGo.transform.position = position; - var boxOverlap = TestBoxOverlapChecker.CreateChecker(gridSizeX: 5, gridSizeZ: 15, rotateWithAgent: true, rootReference: testGo, centerObject: testGo); + var boxOverlap = TestBoxOverlapChecker.CreateChecker(gridSizeX: 5, gridSizeZ: 15, rotateWithAgent: true, agentGameObject: testGo, centerObject: testGo); Assert.AreEqual(new Vector3(-2f, 0, -7f) + position, boxOverlap.GetCellGlobalPosition(0)); Assert.AreEqual(new Vector3(-2f, 0, 7f) + position, boxOverlap.GetCellGlobalPosition(14)); @@ -154,7 +154,7 @@ public void TestBufferResize() var testGo = new GameObject("test"); testGo.transform.position = Vector3.zero; testObjects.Add(testGo); - var boxOverlap = TestBoxOverlapChecker.CreateChecker(rootReference: testGo, centerObject: testGo, initialColliderBufferSize: 2, maxColliderBufferSize: 5); + var boxOverlap = TestBoxOverlapChecker.CreateChecker(agentGameObject: testGo, centerObject: testGo, initialColliderBufferSize: 2, maxColliderBufferSize: 5); boxOverlap.Update(); Assert.AreEqual(2, boxOverlap.ColliderBuffer.Length); @@ -197,7 +197,7 @@ public void TestParseCollidersClosest() cellScaleZ: 10f, gridSizeX: 2, gridSizeZ: 2, - rootReference: testGo, + agentGameObject: testGo, centerObject: testGo, detectableTags: new [] { tag1 }); var helper = new VerifyParseCollidersHelper(); @@ -234,7 +234,7 @@ public void TestParseCollidersAll() cellScaleZ: 10f, gridSizeX: 2, gridSizeZ: 2, - rootReference: testGo, + agentGameObject: testGo, centerObject: testGo, detectableTags: new [] { tag1 }); var helper = new VerifyParseCollidersHelper(); From 7ab082ccb68cfc5eb068a85dbb431e3ec65138f3 Mon Sep 17 00:00:00 2001 From: Ruo-Ping Dong Date: Thu, 22 Apr 2021 10:00:23 -0700 Subject: [PATCH 8/8] update migration guide --- docs/Migrating.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/Migrating.md b/docs/Migrating.md index 8867a7787d9..b014a3fd2ad 100644 --- a/docs/Migrating.md +++ b/docs/Migrating.md @@ -114,7 +114,6 @@ will not work in newer version. Some errors might show up when loading the old s You'll need to remove the old sensor and create a new GridSensor. * These parameters names have changed but still refer to the same concept in the sensor: `GridNumSide` -> `GridSize`, `RotateToAgent` -> `RotateWithAgent`, `ObserveMask` -> `ColliderMask`, `DetectableObjects` -> `DetectableTags` -* `RootReference` is removed and the sensor component's GameObject will always be ignored for hit results. * `DepthType` (`ChanelBase`/`ChannelHot`) option and `ChannelDepth` are removed. Now the default is one-hot encoding for detected tag. If you were using original GridSensor without overriding any method, switching to new GridSensor will produce similar effect for training although the actual observations