Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ public override void OnInspectorGUI()
so.Update();

var rbSensorComp = so.targetObject as RigidBodySensorComponent;
if (rbSensorComp.IsTrivial())
{
EditorGUILayout.HelpBox(
"The Root Body has no Joints, and the Virtual Root is null or the same as the " +
"Root Body's GameObject. This will not generate any useful observations; they will always " +
"be the identity values. Consider removing this component since it won't help the Agent.",
MessageType.Warning
);
}

bool requireExtractorUpdate;

EditorGUI.BeginDisabledGroup(!EditorUtilities.CanUpdateModelProperties());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,24 @@ internal void SetPoseEnabled(int index, bool enabled)
{
GetPoseExtractor().SetPoseEnabled(index, enabled);
}

internal bool IsTrivial()
{
if (ReferenceEquals(RootBody, null))
{
// It *is* trivial, but this will happen when the sensor is being set up, so don't warn then.
return false;
}
var joints = RootBody.GetComponentsInChildren<Joint>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

either need to null check RootBody, or if it's null maybe we just transform.GetComponentsInChildren<Joint>();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the null-check above, so RootBody will always be non-null here.

if (joints.Length == 0)
{
if (ReferenceEquals(VirtualRoot, null) || ReferenceEquals(VirtualRoot, RootBody.gameObject))
{
return true;
}
}
return false;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public void TestNullRootBody()
var gameObj = new GameObject();

var sensorComponent = gameObj.AddComponent<RigidBodySensorComponent>();
Assert.IsFalse(sensorComponent.IsTrivial());
var sensor = sensorComponent.CreateSensors()[0];
SensorTestHelper.CompareObservation(sensor, new float[0]);
}
Expand All @@ -48,6 +49,7 @@ public void TestSingleRigidbody()
UseLocalSpaceTranslations = true,
UseLocalSpaceRotations = true
};
Assert.IsTrue(sensorComponent.IsTrivial());

var sensor = sensorComponent.CreateSensors()[0];
sensor.Update();
Expand Down Expand Up @@ -93,6 +95,7 @@ public void TestBodiesWithJoint()
UseLocalSpaceLinearVelocity = true
};
sensorComponent.VirtualRoot = virtualRoot;
Assert.IsFalse(sensorComponent.IsTrivial());

var sensor = sensorComponent.CreateSensors()[0];
sensor.Update();
Expand Down
1 change: 1 addition & 0 deletions com.unity.ml-agents/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to
#### ml-agents / ml-agents-envs / gym-unity (Python)
- Added a fully connected visual encoder for environments with very small image inputs. (#5351)
### Bug Fixes
- RigidBodySensorComponent now displays a warning if it's used in a way that won't generate useful observations. (#5387)


## [2.0.0-exp.1] - 2021-04-22
Expand Down