Skip to content

Fix GridSensorComponent bug #5270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 15, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion com.unity.ml-agents/Runtime/Sensors/GridSensorComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public int ObservationStacks
/// <inheritdoc/>
public override ISensor[] CreateSensors()
{
List<ISensor> m_Sensors = new List<ISensor>();
m_Sensors = new List<ISensor>();
m_BoxOverlapChecker = new BoxOverlapChecker(
m_CellScale,
m_GridSize,
Expand Down
15 changes: 15 additions & 0 deletions com.unity.ml-agents/Tests/Runtime/Sensor/GridSensorTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#if MLA_UNITY_PHYSICS_MODULE
using System.Collections.Generic;
using System.Collections;
using System.Reflection;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
Expand Down Expand Up @@ -79,6 +81,19 @@ public void TestInvalidCompressionConfiguration()
Assert.AreEqual(gridSensor.CompressionType, SensorCompressionType.None);
}

[Test]
public void TestCreateSensor()
{
testGo.tag = k_Tag2;
string[] tags = { k_Tag1, k_Tag2 };
gridSensorComponent.SetComponentParameters(tags, useGridSensorBase: true);

gridSensorComponent.CreateSensors();
var componentSensor = (List<ISensor>)typeof(GridSensorComponent).GetField("m_Sensors",
BindingFlags.Instance | BindingFlags.NonPublic).GetValue(gridSensorComponent);
Assert.AreEqual(componentSensor.Count, 1);
}

[Test]
public void PerceiveNotSelf()
{
Expand Down