Skip to content

Commit d6bbd2e

Browse files
committed
GetComponent -> TryGetComponent
1 parent 0092d35 commit d6bbd2e

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

org.mixedrealitytoolkit.input/Tests/Runtime/InteractionModeManagerTests.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ public IEnumerator InteractionDetectorTest()
8888
yield return rightHand.AimAt(cube.transform.position);
8989
yield return RuntimeTestUtilities.WaitForUpdates();
9090

91-
InteractionDetector interactionDetector = rightHandController.GetComponentInChildren<MRTKRayInteractor>().GetComponent<InteractionDetector>();
91+
if (!rightHandController.GetComponentInChildren<MRTKRayInteractor>().TryGetComponent(out InteractionDetector interactionDetector))
92+
{
93+
Assert.Fail("No interaction detector found on right hand ray interactor. Is the component missing?");
94+
}
9295

9396
InteractionMode expectedMode = interactionDetector.ModeOnHover;
9497
Assert.AreEqual(expectedMode, interactionDetector.ModeOnDetection);
@@ -147,7 +150,10 @@ public IEnumerator ModeMediationTest()
147150
InputTestUtilities.SetHandAnchorPoint(Handedness.Right, ControllerAnchorPoint.Grab);
148151
yield return RuntimeTestUtilities.WaitForUpdates();
149152

150-
InteractionDetector rayInteractionDetector = rightHandController.GetComponentInChildren<MRTKRayInteractor>().GetComponent<InteractionDetector>();
153+
if (!rightHandController.GetComponentInChildren<MRTKRayInteractor>().TryGetComponent(out InteractionDetector rayInteractionDetector))
154+
{
155+
Assert.Fail("No interaction detector found on right hand ray interactor. Is the component missing?");
156+
}
151157

152158
// Moving the hand to a position where its far ray is hovering over the cube
153159
yield return rightHand.AimAt(cube.transform.position);
@@ -172,7 +178,10 @@ public IEnumerator ModeMediationTest()
172178
yield return rightHand.SetHandshape(HandshapeTypes.HandshapeId.Grab);
173179
yield return RuntimeTestUtilities.WaitForUpdates();
174180

175-
InteractionDetector grabInteractionDetector = rightHandController.GetComponentInChildren<GrabInteractor>().GetComponent<InteractionDetector>();
181+
if (!rightHandController.GetComponentInChildren<GrabInteractor>().TryGetComponent(out InteractionDetector grabInteractionDetector))
182+
{
183+
Assert.Fail("No interaction detector found on right hand grab interactor. Is the component missing?");
184+
}
176185

177186
InteractionMode grabMode = grabInteractionDetector.ModeOnSelect;
178187
Assert.AreEqual(grabMode, grabInteractionDetector.ModeOnDetection);

0 commit comments

Comments
 (0)